Skip to content

Commit 23c133d

Browse files
authored
feat: add config fallback timeout (#620)
1 parent 0c9cf54 commit 23c133d

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

docs/configuration.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ Partytown does not require a config for it to work, however a config can be set
77
| Config | Description |
88
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
99
| `debug` | When `true`, Partytown scripts are not inlined and not minified. See the [Debugging](/debugging) docs on how to enable more logging. |
10-
| `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. |
10+
| `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. |
1111
| `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/` |
1212
| `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/]`.|
1313
| `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. |
1414
| `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). |
15+
| `fallbackTimeout` | A timeout in ms until Partytown initialization is considered as failed & fallbacks to the regular execution in main thread. Default is 9999 |
1516

1617
## Vanilla Config
1718

src/integration/api.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface PartytownConfig {
2020
// (undocumented)
2121
apply?: ApplyHook;
2222
debug?: boolean;
23+
fallbackTimeout?: number;
2324
forward?: PartytownForwardProperty[];
2425
// (undocumented)
2526
get?: GetHook;

src/lib/main/snippet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function snippet(
4141
top!.dispatchEvent(new CustomEvent('pt1', { detail: win }));
4242
} else {
4343
// set a timeout to fire if PT hasn't initialized in Xms
44-
timeout = setTimeout(fallback, 9999);
44+
timeout = setTimeout(fallback, config?.fallbackTimeout || 9999);
4545
doc.addEventListener('pt0', clearFallback);
4646

4747
if (useAtomics) {

src/lib/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ export interface PartytownConfig {
444444
* https://partytown.builder.io/forwarding-events
445445
*/
446446
forward?: PartytownForwardProperty[];
447+
/**
448+
* Timeout in ms before the initialization considered failed and the fallback solution is executed
449+
* Default: 9999
450+
*/
451+
fallbackTimeout?: number;
447452
/**
448453
* The css selector where the sandbox should be placed.
449454
* Default: body

0 commit comments

Comments
 (0)