Skip to content

Commit

Permalink
feat: add config fallback timeout (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaa123eee authored Nov 18, 2024
1 parent 0c9cf54 commit 23c133d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/integration/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface PartytownConfig {
// (undocumented)
apply?: ApplyHook;
debug?: boolean;
fallbackTimeout?: number;
forward?: PartytownForwardProperty[];
// (undocumented)
get?: GetHook;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/main/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23c133d

Please sign in to comment.