diff --git a/docs/configuration.md b/docs/configuration.md index b83a0867..a12288f9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -7,11 +7,12 @@ Partytown does not require a config for it to work, however a config can be set | Config | Description | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `debug` | When `true`, Partytown scripts are not inlined and not minified. See the [Debugging](/debugging) docs on how to enable more logging. | -| `forward` | An array of strings representing function calls on the main thread to forward to the web worker. See [Forwarding Events and Triggers](/forwarding-events) for more info. | +| `forward` | An array of strings representing function calls on the main thread to forward to the web worker. See [Forwarding Events and Triggers](/forwarding-events) for more info. | | `lib` | Path where the Partytown library can be found your server. Note that the path must both start and end with a `/` character, and the files must be hosted from the same origin as the webpage. Default is `/~partytown/` | | `loadScriptsOnMainThread` | An array of strings or regular expressions (RegExp) used to filter out which script are executed via Partytown and the main thread. An example is as follows: `loadScriptsOnMainThread: ["https://test.com/analytics.js", "inline-script-id", /regex-matched-script\.js/]`.| | `resolveUrl` | Hook that is called to resolve URLs which can be used to modify URLs. The hook uses the API: `resolveUrl(url: URL, location: URL, method: string)`. See the [Proxying Requests](/proxying-requests) for more information. | | `nonce` | The nonce property may be set on script elements created by Partytown. This should be set only when dealing with content security policies and when the use of `unsafe-inline` is disabled (using `nonce-*` instead). | +| `fallbackTimeout` | A timeout in ms until Partytown initialization is considered as failed & fallbacks to the regular execution in main thread. Default is 9999 | ## Vanilla Config diff --git a/src/integration/api.md b/src/integration/api.md index 9ffe0f06..21dfd32a 100644 --- a/src/integration/api.md +++ b/src/integration/api.md @@ -20,6 +20,7 @@ export interface PartytownConfig { // (undocumented) apply?: ApplyHook; debug?: boolean; + fallbackTimeout?: number; forward?: PartytownForwardProperty[]; // (undocumented) get?: GetHook; diff --git a/src/lib/main/snippet.ts b/src/lib/main/snippet.ts index 5cbc07b0..d0bdb7c9 100644 --- a/src/lib/main/snippet.ts +++ b/src/lib/main/snippet.ts @@ -41,7 +41,7 @@ export function snippet( top!.dispatchEvent(new CustomEvent('pt1', { detail: win })); } else { // set a timeout to fire if PT hasn't initialized in Xms - timeout = setTimeout(fallback, 9999); + timeout = setTimeout(fallback, config?.fallbackTimeout || 9999); doc.addEventListener('pt0', clearFallback); if (useAtomics) { diff --git a/src/lib/types.ts b/src/lib/types.ts index 42d95dcd..91060e19 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -444,6 +444,11 @@ export interface PartytownConfig { * https://partytown.builder.io/forwarding-events */ forward?: PartytownForwardProperty[]; + /** + * Timeout in ms before the initialization considered failed and the fallback solution is executed + * Default: 9999 + */ + fallbackTimeout?: number; /** * The css selector where the sandbox should be placed. * Default: body