1 | /**
|
2 | * @public
|
3 | */
|
4 | export declare type ApplyHook = (opts: ApplyHookOptions) => any;
|
5 |
|
6 | /**
|
7 | * @public
|
8 | */
|
9 | declare interface ApplyHookOptions extends HookOptions {
|
10 | args: any[];
|
11 | }
|
12 |
|
13 | declare const ApplyPathKey: unique symbol;
|
14 |
|
15 | /**
|
16 | * @public
|
17 | */
|
18 | export declare type GetHook = (opts: GetHookOptions) => any;
|
19 |
|
20 | /**
|
21 | * @public
|
22 | */
|
23 | declare interface GetHookOptions extends HookOptions {
|
24 | }
|
25 |
|
26 | declare interface HookOptions {
|
27 | name: string;
|
28 | continue: Symbol;
|
29 | nodeName: string | undefined;
|
30 | constructor: string | undefined;
|
31 | instance: WorkerInstance;
|
32 | window: Window;
|
33 | }
|
34 |
|
35 | declare const InstanceDataKey: unique symbol;
|
36 |
|
37 | declare type InstanceId = string;
|
38 |
|
39 | declare const InstanceIdKey: unique symbol;
|
40 |
|
41 | declare const InstanceStateKey: unique symbol;
|
42 |
|
43 | declare const NamespaceKey: unique symbol;
|
44 |
|
45 | /**
|
46 | * https://partytown.builder.io/configuration
|
47 | *
|
48 | * @public
|
49 | */
|
50 | export declare interface PartytownConfig {
|
51 | /**
|
52 | * The `resolveUrl()` hook can be used to modify the URL about to be
|
53 | * requested, which could be used to rewrite urls so they go through a proxy.
|
54 | *
|
55 | * https://partytown.builder.io/proxying-requests
|
56 | *
|
57 | * @param url - The URL to be resolved. This is a URL https://developer.mozilla.org/en-US/docs/Web/API/URL, not a string.
|
58 | * @param location - The current window location.
|
59 | * @param type - The type of resource the url is being resolved for. For example, `fetch` is the value when resolving for `fetch()`, and `a` would be the value when resolving for an anchor element's `href`.
|
60 | * @returns The returned value must be a URL interface, otherwise the default resolved URL is used.
|
61 | */
|
62 | resolveUrl?(url: URL, location: Location, type: ResolveUrlType): URL | undefined | null;
|
63 | /**
|
64 | * When set to `true`, Partytown scripts are not inlined and not minified.
|
65 | *
|
66 | * https://partytown.builder.io/debugging
|
67 | */
|
68 | debug?: boolean;
|
69 | /**
|
70 | * Many third-party scripts provide a global variable which user code calls
|
71 | * in order to send data to the service. For example, Google Tag Manager uses
|
72 | * a [Data Layer](https://developers.google.com/tag-manager/devguide) array,
|
73 | * and by pushing data to the array, the data is then sent on to GTM. Because
|
74 | * we're moving third-party scripts to a web worker, the main thread needs to
|
75 | * know which variables to patch first, and when Partytown loads, it can then
|
76 | * forward the event data on to the service.
|
77 | *
|
78 | * Below is an example of Google Tag Manager and Facebook Pixel:
|
79 | *
|
80 | * ```js
|
81 | * ['dataLayer.push', 'fbq']
|
82 | * ```
|
83 | *
|
84 | * https://partytown.builder.io/forwarding-events
|
85 | */
|
86 | forward?: PartytownForwardProperty[];
|
87 | /**
|
88 | * The css selector where the sandbox should be placed.
|
89 | * Default: body
|
90 | */
|
91 | sandboxParent?: string;
|
92 | mainWindowAccessors?: string[];
|
93 | /**
|
94 | * Rarely, a script will add a named function to the global scope with the
|
95 | * intent that other scripts can call the named function (like Adobe Launch).
|
96 | * Due to how Partytown scopes each script, these named functions do not get
|
97 | * added to `window`. The `globalFns` config can be used to manually ensure
|
98 | * each function is added to the global scope. Consider this an escape hatch
|
99 | * when a third-party script rudely pollutes `window` with functions.
|
100 | */
|
101 | globalFns?: string[];
|
102 | /**
|
103 | * This array can be used to filter which script are executed via
|
104 | * Partytown and which you would like to execute on the main thread.
|
105 | *
|
106 | * @example loadScriptsOnMainThread:['https://test.com/analytics.js', 'inline-script-id']
|
107 | * // Loads the `https://test.com/analytics.js` script on the main thread
|
108 | */
|
109 | loadScriptsOnMainThread?: string[];
|
110 | get?: GetHook;
|
111 | set?: SetHook;
|
112 | apply?: ApplyHook;
|
113 | /**
|
114 | * An absolute path to the root directory which Partytown library files
|
115 | * can be found. The library path must start and end with a `/`.
|
116 | * By default the files will load from the server's `/~partytown/` directory.
|
117 | * Note that the library path must be on the same origin as the html document,
|
118 | * and is also used as the `scope` of the Partytown service worker.
|
119 | */
|
120 | lib?: string;
|
121 | /**
|
122 | * Log method calls (debug mode required)
|
123 | */
|
124 | logCalls?: boolean;
|
125 | /**
|
126 | * Log getter calls (debug mode required)
|
127 | */
|
128 | logGetters?: boolean;
|
129 | /**
|
130 | * Log setter calls (debug mode required)
|
131 | */
|
132 | logSetters?: boolean;
|
133 | /**
|
134 | * Log Image() src requests (debug mode required)
|
135 | */
|
136 | logImageRequests?: boolean;
|
137 | /**
|
138 | * Log calls to main access, which also shows how many tasks were sent per message (debug mode required)
|
139 | */
|
140 | logMainAccess?: boolean;
|
141 | /**
|
142 | * Log script executions (debug mode required)
|
143 | */
|
144 | logScriptExecution?: boolean;
|
145 | /**
|
146 | * Log navigator.sendBeacon() requests (debug mode required)
|
147 | */
|
148 | logSendBeaconRequests?: boolean;
|
149 | /**
|
150 | * Log stack traces (debug mode required)
|
151 | */
|
152 | logStackTraces?: boolean;
|
153 | /**
|
154 | * Path to the service worker file. Defaults to `partytown-sw.js`.
|
155 | */
|
156 | swPath?: string;
|
157 | }
|
158 |
|
159 | /**
|
160 | * A foward property to patch on `window`. The foward config property is an string,
|
161 | * representing the call to forward, such as `dataLayer.push` or `fbq`.
|
162 | *
|
163 | * https://partytown.builder.io/forwarding-events
|
164 | *
|
165 | * @public
|
166 | */
|
167 | export declare type PartytownForwardProperty = string;
|
168 |
|
169 | /**
|
170 | * Function that returns the Partytown snippet as a string, which can be
|
171 | * used as the innerHTML of the inlined Partytown script in the head.
|
172 | *
|
173 | * @public
|
174 | */
|
175 | export declare const partytownSnippet: (config?: PartytownConfig | undefined) => string;
|
176 |
|
177 | /**
|
178 | * @public
|
179 | */
|
180 | export declare type ResolveUrlType = 'fetch' | 'xhr' | 'script' | 'iframe' | 'image';
|
181 |
|
182 | /**
|
183 | * The `type` attribute for Partytown scripts, which does two things:
|
184 | *
|
185 | * 1. Prevents the `<script>` from executing on the main thread.
|
186 | * 2. Is used as a selector so the Partytown library can find all scripts to execute in a web worker.
|
187 | *
|
188 | * @public
|
189 | */
|
190 | export declare const SCRIPT_TYPE = "text/partytown";
|
191 |
|
192 | /**
|
193 | * @public
|
194 | */
|
195 | export declare type SetHook = (opts: SetHookOptions) => any;
|
196 |
|
197 | /**
|
198 | * @public
|
199 | */
|
200 | declare interface SetHookOptions extends HookOptions {
|
201 | value: any;
|
202 | prevent: Symbol;
|
203 | }
|
204 |
|
205 | declare type WinId = string;
|
206 |
|
207 | declare const WinIdKey: unique symbol;
|
208 |
|
209 | declare interface WorkerInstance {
|
210 | [WinIdKey]: WinId;
|
211 | [InstanceIdKey]: InstanceId;
|
212 | [ApplyPathKey]: string[];
|
213 | [InstanceDataKey]: string | undefined;
|
214 | [NamespaceKey]: string | undefined;
|
215 | [InstanceStateKey]: {
|
216 | [key: string]: any;
|
217 | };
|
218 | }
|
219 |
|
220 | export { }
|