wxt 0.8.4 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +3 -2
  2. package/dist/browser.js +3 -4
  3. package/dist/chunk-FNTE2L27.js +7 -0
  4. package/dist/chunk-VFZ5667B.js +2410 -0
  5. package/dist/chunk-YUG22S6W.js +38 -0
  6. package/dist/cli.cjs +3941 -3775
  7. package/dist/cli.d.cts +2 -0
  8. package/dist/client.d.ts +5 -171
  9. package/dist/client.js +128 -131
  10. package/dist/execa-WKZHVHC5.js +2043 -0
  11. package/dist/external-9107db91.d.ts +176 -0
  12. package/dist/external-cb0967d6.d.ts +572 -0
  13. package/dist/index.cjs +2727 -2355
  14. package/dist/index.d.cts +36 -583
  15. package/dist/index.d.ts +36 -583
  16. package/dist/index.js +330 -4484
  17. package/dist/sandbox.d.ts +2 -23
  18. package/dist/sandbox.js +1 -2
  19. package/dist/testing.cjs +161 -35
  20. package/dist/testing.d.cts +7 -273
  21. package/dist/testing.d.ts +7 -273
  22. package/dist/testing.js +12 -676
  23. package/dist/{virtual-modules → virtual}/background-entrypoint.js +6 -7
  24. package/dist/{virtual-modules → virtual}/content-script-entrypoint.js +4 -5
  25. package/dist/virtual/mock-browser.js +152 -0
  26. package/dist/{virtual-modules → virtual}/reload-html.js +2 -3
  27. package/dist/{virtual-modules → virtual}/unlisted-script-entrypoint.js +2 -3
  28. package/package.json +6 -5
  29. package/dist/index.cjs.map +0 -1
  30. package/dist/index.js.map +0 -1
  31. package/dist/virtual-modules/background-entrypoint.js.map +0 -1
  32. package/dist/virtual-modules/content-script-entrypoint.js.map +0 -1
  33. package/dist/virtual-modules/fake-browser.cjs +0 -31
  34. package/dist/virtual-modules/fake-browser.js +0 -8
  35. package/dist/virtual-modules/reload-html.js.map +0 -1
  36. package/dist/virtual-modules/unlisted-script-entrypoint.js.map +0 -1
@@ -0,0 +1,176 @@
1
+ import { Manifest } from 'webextension-polyfill';
2
+
3
+ /**
4
+ * Implements [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
5
+ * Used to detect and stop content script code when the script is invalidated.
6
+ *
7
+ * It also provides several utilities like `ctx.setTimeout` and `ctx.setInterval` that should be used in
8
+ * content scripts instead of `window.setTimeout` or `window.setInterval`.
9
+ */
10
+ declare class ContentScriptContext implements AbortController {
11
+ #private;
12
+ private readonly contentScriptName;
13
+ readonly options?: Omit<ContentScriptDefinition, "main"> | undefined;
14
+ private static SCRIPT_STARTED_MESSAGE_TYPE;
15
+ constructor(contentScriptName: string, options?: Omit<ContentScriptDefinition, "main"> | undefined);
16
+ get signal(): AbortSignal;
17
+ abort(reason?: any): void;
18
+ get isInvalid(): boolean;
19
+ get isValid(): boolean;
20
+ /**
21
+ * Add a listener that is called when the content script's context is invalidated.
22
+ *
23
+ * @returns A function to remove the listener.
24
+ *
25
+ * @example
26
+ * browser.runtime.onMessage.addListener(cb);
27
+ * const removeInvalidatedListener = ctx.onInvalidated(() => {
28
+ * browser.runtime.onMessage.removeListener(cb);
29
+ * })
30
+ * // ...
31
+ * removeInvalidatedListener();
32
+ */
33
+ onInvalidated(cb: () => void): () => void;
34
+ /**
35
+ * Return a promise that never resolves. Useful if you have an async function that shouldn't run
36
+ * after the context is expired.
37
+ *
38
+ * @example
39
+ * const getValueFromStorage = async () => {
40
+ * if (ctx.isInvalid) return ctx.block();
41
+ *
42
+ * // ...
43
+ * }
44
+ */
45
+ block<T>(): Promise<T>;
46
+ /**
47
+ * Wrapper around `window.setInterval` that automatically clears the interval when invalidated.
48
+ */
49
+ setInterval(handler: () => void, timeout?: number): number;
50
+ /**
51
+ * Wrapper around `window.setTimeout` that automatically clears the interval when invalidated.
52
+ */
53
+ setTimeout(handler: () => void, timeout?: number): number;
54
+ /**
55
+ * Wrapper around `window.requestAnimationFrame` that automatically cancels the request when
56
+ * invalidated.
57
+ */
58
+ requestAnimationFrame(callback: FrameRequestCallback): number;
59
+ /**
60
+ * Wrapper around `window.requestIdleCallback` that automatically cancels the request when
61
+ * invalidated.
62
+ */
63
+ requestIdleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): number;
64
+ /**
65
+ * Call `target.addEventListener` and remove the event listener when the context is invalidated.
66
+ *
67
+ * @example
68
+ * ctx.addEventListener(window, "mousemove", () => {
69
+ * // ...
70
+ * });
71
+ * ctx.addEventListener(document, "visibilitychange", () => {
72
+ * // ...
73
+ * });
74
+ */
75
+ addEventListener(target: any, type: string, handler: (event: Event) => void, options?: AddEventListenerOptions): void;
76
+ /**
77
+ * @internal
78
+ * Abort the abort controller and execute all `onInvalidated` listeners.
79
+ */
80
+ notifyInvalidated(): void;
81
+ }
82
+
83
+ type TargetBrowser = string;
84
+ interface ContentScriptDefinition extends ExcludableEntrypoint {
85
+ matches: PerBrowserOption<Manifest.ContentScript['matches']>;
86
+ /**
87
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
88
+ * @default "documentIdle"
89
+ */
90
+ runAt?: PerBrowserOption<Manifest.ContentScript['run_at']>;
91
+ /**
92
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
93
+ * @default false
94
+ */
95
+ matchAboutBlank?: PerBrowserOption<Manifest.ContentScript['match_about_blank']>;
96
+ /**
97
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
98
+ * @default []
99
+ */
100
+ excludeMatches?: PerBrowserOption<Manifest.ContentScript['exclude_matches']>;
101
+ /**
102
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
103
+ * @default []
104
+ */
105
+ includeGlobs?: PerBrowserOption<Manifest.ContentScript['include_globs']>;
106
+ /**
107
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
108
+ * @default []
109
+ */
110
+ excludeGlobs?: PerBrowserOption<Manifest.ContentScript['exclude_globs']>;
111
+ /**
112
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
113
+ * @default false
114
+ */
115
+ allFrames?: PerBrowserOption<Manifest.ContentScript['all_frames']>;
116
+ /**
117
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
118
+ * @default false
119
+ */
120
+ matchOriginAsFallback?: PerBrowserOption<boolean>;
121
+ /**
122
+ * See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
123
+ * @default "ISOLATED"
124
+ */
125
+ world?: PerBrowserOption<'ISOLATED' | 'MAIN'>;
126
+ /**
127
+ * Customize how imported/generated styles are injected with the content script. Regardless of the
128
+ * mode selected, CSS will always be built and included in the output directory.
129
+ *
130
+ * - `"manifest"` - Include the CSS in the manifest, under the content script's `css` array.
131
+ * - `"manual"` - Exclude the CSS from the manifest. You are responsible for manually loading it
132
+ * onto the page. Use `browser.runtime.getURL("content-scripts/<name>.css")` to get the file's
133
+ * URL
134
+ * - `"ui"` - Exclude the CSS from the manifest. CSS will be automatically added to your UI when
135
+ * calling `createContentScriptUi`
136
+ *
137
+ * @default "manifest"
138
+ */
139
+ cssInjectionMode?: PerBrowserOption<'manifest' | 'manual' | 'ui'>;
140
+ /**
141
+ * Main function executed when the content script is loaded.
142
+ */
143
+ main(ctx: ContentScriptContext): void | Promise<void>;
144
+ }
145
+ interface BackgroundDefinition extends ExcludableEntrypoint {
146
+ type?: PerBrowserOption<'module'>;
147
+ persistent?: PerBrowserOption<boolean>;
148
+ main(): void;
149
+ }
150
+ interface UnlistedScriptDefinition extends ExcludableEntrypoint {
151
+ /**
152
+ * Main function executed when the unlisted script is ran.
153
+ */
154
+ main(): void | Promise<void>;
155
+ }
156
+ type PerBrowserOption<T> = T | {
157
+ [browser: TargetBrowser]: T;
158
+ };
159
+ interface ExcludableEntrypoint {
160
+ /**
161
+ * List of target browsers to include this entrypoint in. Defaults to being included in all
162
+ * builds. Cannot be used with `exclude`. You must choose one of the two options.
163
+ *
164
+ * @default undefined
165
+ */
166
+ include?: TargetBrowser[];
167
+ /**
168
+ * List of target browsers to exclude this entrypoint from. Cannot be used with `include`. You
169
+ * must choose one of the two options.
170
+ *
171
+ * @default undefined
172
+ */
173
+ exclude?: TargetBrowser[];
174
+ }
175
+
176
+ export { BackgroundDefinition as B, ContentScriptContext as C, UnlistedScriptDefinition as U, ContentScriptDefinition as a };