# Web SDK errors

> Every TryYourSizeError code of TryYourSize.js and @tryyoursize/react, what causes it and how to fix it.

Source: https://docs.tryyoursize.com/sdk/errors/

TryYourSize.js throws (or emits with the `loaderror` event) a [`TryYourSizeError`](https://docs.tryyoursize.com/reference/web/tryyoursize-error.md) with a stable `type` and `code`, a `message`, and a `docUrl` that points at the matching section below.

| Type | Meaning |
|---|---|
| `integration_error` | Your code called the SDK wrongly. Thrown synchronously; fix the call. |
| `load_error` | Our window or script could not be loaded or reached: network, Content Security Policy, an origin not registered for the key. Emitted with `loaderror`, or a rejected promise. |

```js
try {
  const tys = TryYourSize(window.TYS_KEY);
} catch (e) {
  console.error(e.code, e.docUrl);
}
```

## secret_key_in_browser

You passed a secret key (`sk_…`) to `TryYourSize()`. Secret keys must never reach a browser: anyone could read them. Use your **publishable** key (`pk_test_…` / `pk_live_…`) and [roll the secret key](https://docs.tryyoursize.com/get-started/keys-and-modes.md) if it was deployed.

## invalid_key

The key is not a publishable key (`pk_test_…` or `pk_live_…` followed by at least 8 characters). Copy it again from Studio → Developers → API keys.

## mount_not_found

`element.mount(target)` found nothing: the selector matched no element, or it ran before the element was in the page. Mount after the container exists (for example after `DOMContentLoaded`, or in your framework's mounted hook).

## already_mounted

The element is already mounted. Call `unmount()` first, or create a second element (several of one type are allowed).

## element_destroyed

The element was destroyed with `destroy()`. Create a new one with `elements.create()`.

## unknown_element_type

`elements.create(type)` got a type that does not exist. Use `"sizeGuide"`, `"button"` or `"fit"`.

## invalid_option

An option is missing or invalid: `product` is required; `variant` must be `"link"` or `"button"`; `label` is a string of at most 60 characters; `demo` needs a test key and `{ body: "sample-female-165" }`; `recommendation()` needs a product. The message names the option.

## window_unreachable

Our window did not load or connect within 15 seconds. Emitted with `loaderror`. Check, in this order:

1. Your Content Security Policy allows `frame-src https://embed.tryyoursize.com` (and `script-src https://js.tryyoursize.com` for the CDN build).
2. The page's origin is registered for the key's mode in Studio (Settings → Stores → Allowed sites). `http://localhost` works in test mode without registering.
3. The network: an ad blocker or a corporate proxy blocking `tryyoursize.com`.

See [Troubleshooting](https://docs.tryyoursize.com/guides/troubleshooting.md#the-element-does-not-appear).

## script_load_failed

`loadTryYourSize()` could not load `https://js.tryyoursize.com/v1/tys.js` (network, CSP `script-src`). The promise rejects; call `loadTryYourSize()` again to retry.
