wxt 0.19.29 → 0.20.0-beta2
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.
- package/dist/browser.d.ts +30 -0
- package/dist/browser.mjs +3 -0
- package/dist/builtin-modules/unimport.mjs +29 -10
- package/dist/cli/index.mjs +0 -1
- package/dist/core/builders/vite/index.mjs +17 -37
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +1 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +2 -4
- package/dist/core/builders/vite/plugins/index.d.ts +0 -1
- package/dist/core/builders/vite/plugins/index.mjs +0 -1
- package/dist/core/builders/vite/plugins/noopBackground.mjs +1 -1
- package/dist/core/define-web-ext-config.d.ts +9 -0
- package/dist/core/define-web-ext-config.mjs +10 -0
- package/dist/core/generate-wxt-dir.mjs +3 -6
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.mjs +1 -1
- package/dist/core/resolve-config.mjs +142 -49
- package/dist/core/utils/building/index.d.ts +0 -1
- package/dist/core/utils/building/index.mjs +0 -1
- package/dist/core/utils/building/rebuild.d.ts +2 -2
- package/dist/core/utils/content-scripts.d.ts +4 -3
- package/dist/core/utils/content-scripts.mjs +2 -0
- package/dist/core/utils/manifest.d.ts +4 -8
- package/dist/core/utils/manifest.mjs +4 -7
- package/dist/core/utils/strings.d.ts +0 -4
- package/dist/core/utils/strings.mjs +0 -6
- package/dist/core/utils/testing/fake-objects.d.ts +3376 -1013
- package/dist/core/utils/testing/fake-objects.mjs +19 -22
- package/dist/core/utils/transform.d.ts +1 -1
- package/dist/core/utils/types.d.ts +3 -0
- package/dist/index.d.ts +5 -0
- package/dist/modules.d.ts +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/wxt-vitest-plugin.mjs +1 -3
- package/dist/types.d.ts +42 -76
- package/dist/utils/app-config.d.ts +2 -0
- package/dist/{client/content-scripts → utils}/content-script-context.d.ts +4 -3
- package/dist/{client/content-scripts → utils}/content-script-context.mjs +5 -3
- package/dist/utils/content-script-ui/iframe.d.ts +32 -0
- package/dist/utils/content-script-ui/iframe.mjs +30 -0
- package/dist/utils/content-script-ui/integrated.d.ts +34 -0
- package/dist/utils/content-script-ui/integrated.mjs +32 -0
- package/dist/utils/content-script-ui/shadow-root.d.ts +76 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +73 -0
- package/dist/utils/content-script-ui/shared.d.ts +5 -0
- package/dist/{client/content-scripts/ui/index.mjs → utils/content-script-ui/shared.mjs} +5 -138
- package/dist/{client/content-scripts/ui → utils/content-script-ui}/types.d.ts +1 -96
- package/dist/{sandbox → utils}/define-app-config.d.ts +3 -2
- package/dist/{sandbox → utils}/define-background.d.ts +1 -0
- package/dist/{sandbox → utils}/define-content-script.d.ts +1 -0
- package/dist/{sandbox → utils}/define-unlisted-script.d.ts +1 -0
- package/dist/{sandbox → utils}/define-wxt-plugin.d.ts +1 -0
- package/dist/{sandbox → utils/internal}/dev-server-websocket.mjs +1 -1
- package/dist/{client/content-scripts → utils/internal}/location-watcher.d.ts +1 -1
- package/dist/utils/match-patterns.d.ts +5 -0
- package/dist/utils/match-patterns.mjs +1 -0
- package/dist/utils/storage.d.ts +5 -0
- package/dist/version.mjs +1 -1
- package/dist/virtual/background-entrypoint.mjs +1 -1
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +1 -1
- package/package.json +109 -76
- package/dist/browser/chrome.d.ts +0 -13
- package/dist/browser/chrome.mjs +0 -7
- package/dist/browser/index.d.ts +0 -26
- package/dist/browser/index.mjs +0 -2
- package/dist/client/app-config.d.ts +0 -2
- package/dist/client/content-scripts/index.d.ts +0 -2
- package/dist/client/content-scripts/index.mjs +0 -2
- package/dist/client/content-scripts/ui/index.d.ts +0 -23
- package/dist/client/index.d.ts +0 -8
- package/dist/client/index.mjs +0 -3
- package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +0 -10
- package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +0 -15
- package/dist/core/define-runner-config.d.ts +0 -2
- package/dist/core/define-runner-config.mjs +0 -3
- package/dist/core/utils/building/import-entrypoint.d.ts +0 -16
- package/dist/core/utils/building/import-entrypoint.mjs +0 -99
- package/dist/sandbox/index.d.ts +0 -11
- package/dist/sandbox/index.mjs +0 -6
- package/dist/storage.d.ts +0 -4
- /package/dist/{client → utils}/app-config.mjs +0 -0
- /package/dist/{client/content-scripts/ui → utils/content-script-ui}/types.mjs +0 -0
- /package/dist/{sandbox → utils}/define-app-config.mjs +0 -0
- /package/dist/{sandbox → utils}/define-background.mjs +0 -0
- /package/dist/{sandbox → utils}/define-content-script.mjs +0 -0
- /package/dist/{sandbox → utils}/define-unlisted-script.mjs +0 -0
- /package/dist/{sandbox → utils}/define-wxt-plugin.mjs +0 -0
- /package/dist/{client → utils}/inject-script.d.ts +0 -0
- /package/dist/{client → utils}/inject-script.mjs +0 -0
- /package/dist/{client/content-scripts → utils/internal}/custom-events.d.ts +0 -0
- /package/dist/{client/content-scripts → utils/internal}/custom-events.mjs +0 -0
- /package/dist/{sandbox → utils/internal}/dev-server-websocket.d.ts +0 -0
- /package/dist/{client/content-scripts → utils/internal}/location-watcher.mjs +0 -0
- /package/dist/{sandbox/utils → utils/internal}/logger.d.ts +0 -0
- /package/dist/{sandbox/utils → utils/internal}/logger.mjs +0 -0
- /package/dist/{storage.mjs → utils/storage.mjs} +0 -0
|
@@ -160,13 +160,11 @@ export const fakeOutputAsset = fakeObjectCreator(() => ({
|
|
|
160
160
|
export function fakeOutputFile() {
|
|
161
161
|
return faker.helpers.arrayElement([fakeOutputAsset(), fakeOutputChunk()]);
|
|
162
162
|
}
|
|
163
|
-
export const fakeManifest = fakeObjectCreator(
|
|
164
|
-
()
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
})
|
|
169
|
-
);
|
|
163
|
+
export const fakeManifest = fakeObjectCreator(() => ({
|
|
164
|
+
manifest_version: faker.helpers.arrayElement([2, 3]),
|
|
165
|
+
name: faker.string.alphanumeric(),
|
|
166
|
+
version: `${faker.number.int()}.${faker.number.int()}.${faker.number.int()}`
|
|
167
|
+
}));
|
|
170
168
|
export const fakeUserManifest = fakeObjectCreator(() => ({
|
|
171
169
|
name: faker.string.alphanumeric(),
|
|
172
170
|
version: `${faker.number.int()}.${faker.number.int()}.${faker.number.int()}`
|
|
@@ -193,6 +191,7 @@ export const fakeResolvedConfig = fakeObjectCreator(() => {
|
|
|
193
191
|
env: { browser, command, manifestVersion, mode },
|
|
194
192
|
fsCache: mock(),
|
|
195
193
|
imports: {
|
|
194
|
+
disabled: faker.datatype.boolean(),
|
|
196
195
|
eslintrc: {
|
|
197
196
|
enabled: faker.helpers.arrayElement([false, 8, 9]),
|
|
198
197
|
filePath: fakeFile(),
|
|
@@ -244,12 +243,8 @@ export const fakeResolvedConfig = fakeObjectCreator(() => {
|
|
|
244
243
|
compressionLevel: 9,
|
|
245
244
|
zipSources: false
|
|
246
245
|
},
|
|
247
|
-
transformManifest: () => {
|
|
248
|
-
},
|
|
249
246
|
userConfigMetadata: {},
|
|
250
247
|
alias: {},
|
|
251
|
-
extensionApi: "webextension-polyfill",
|
|
252
|
-
entrypointLoader: "vite-node",
|
|
253
248
|
experimental: {},
|
|
254
249
|
dev: {
|
|
255
250
|
reloadCommand: "Alt+R"
|
|
@@ -299,17 +294,19 @@ export const fakeBuildStepOutput = fakeObjectCreator(() => ({
|
|
|
299
294
|
chunks: fakeArray(fakeOutputChunk),
|
|
300
295
|
entrypoints: fakeArray(fakeEntrypoint)
|
|
301
296
|
}));
|
|
302
|
-
export const fakeManifestCommand = fakeObjectCreator(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
{
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
297
|
+
export const fakeManifestCommand = fakeObjectCreator(
|
|
298
|
+
() => ({
|
|
299
|
+
description: faker.string.sample(),
|
|
300
|
+
suggested_key: {
|
|
301
|
+
default: `${faker.helpers.arrayElement(["ctrl", "alt"])}+${faker.number.int(
|
|
302
|
+
{
|
|
303
|
+
min: 0,
|
|
304
|
+
max: 9
|
|
305
|
+
}
|
|
306
|
+
)}`
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
);
|
|
313
310
|
export const fakeDevServer = fakeObjectCreator(() => ({
|
|
314
311
|
hostname: "localhost",
|
|
315
312
|
origin: "http://localhost",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 1. Removes or clears out `main` function from returned object
|
|
4
4
|
* 2. Removes any unused functions/variables outside the definition that aren't being called/used
|
|
5
5
|
* 3. Removes unused imports
|
|
6
|
-
* 3. Removes value-less, side-effect only imports (like `import "./styles.css"` or `import "
|
|
6
|
+
* 3. Removes value-less, side-effect only imports (like `import "./styles.css"` or `import "polyfill"`)
|
|
7
7
|
*/
|
|
8
8
|
export declare function removeMainFunctionCode(code: string): {
|
|
9
9
|
code: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Browser } from '@wxt-dev/browser';
|
|
1
2
|
/**
|
|
2
3
|
* Remove optional from key, but keep undefined if present
|
|
3
4
|
*
|
|
@@ -8,3 +9,5 @@
|
|
|
8
9
|
export type NullablyRequired<T> = {
|
|
9
10
|
[K in keyof Required<T>]: T[K];
|
|
10
11
|
};
|
|
12
|
+
export type ManifestContentScript = NonNullable<Browser.runtime.Manifest['content_scripts']>[number];
|
|
13
|
+
export type ManifestV3WebAccessibleResource = NonNullable<Browser.runtime.ManifestV3['web_accessible_resources']>[number];
|
package/dist/index.d.ts
CHANGED
package/dist/modules.d.ts
CHANGED
package/dist/testing/index.d.ts
CHANGED
|
@@ -16,8 +16,6 @@ export async function WxtVitest(inlineConfig) {
|
|
|
16
16
|
resolveAppConfig(wxt.config),
|
|
17
17
|
extensionApiMock(wxt.config)
|
|
18
18
|
];
|
|
19
|
-
|
|
20
|
-
plugins.push(UnimportPlugin.vite(wxt.config.imports));
|
|
21
|
-
}
|
|
19
|
+
plugins.push(UnimportPlugin.vite(wxt.config.imports));
|
|
22
20
|
return plugins;
|
|
23
21
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
|
-
import type { Manifest, Scripting } from 'wxt/browser';
|
|
3
2
|
import { UnimportOptions, Import } from 'unimport';
|
|
4
3
|
import { LogLevel } from 'consola';
|
|
5
|
-
import type { ContentScriptContext } from './
|
|
4
|
+
import type { ContentScriptContext } from './utils/content-script-context';
|
|
6
5
|
import type { PluginVisualizerOptions } from '@aklinker1/rollup-plugin-visualizer';
|
|
7
6
|
import { ResolvedConfig as C12ResolvedConfig } from 'c12';
|
|
8
7
|
import { Hookable, NestedHooks } from 'hookable';
|
|
9
8
|
import type * as Nypm from 'nypm';
|
|
9
|
+
import { ManifestContentScript } from './core/utils/types';
|
|
10
|
+
import type { Browser } from '@wxt-dev/browser';
|
|
10
11
|
export interface InlineConfig {
|
|
11
12
|
/**
|
|
12
13
|
* Your project's root directory containing the `package.json` used to fill out the
|
|
@@ -36,7 +37,7 @@ export interface InlineConfig {
|
|
|
36
37
|
*/
|
|
37
38
|
entrypointsDir?: string;
|
|
38
39
|
/**
|
|
39
|
-
* @default "${config.
|
|
40
|
+
* @default "${config.root}/modules"
|
|
40
41
|
*/
|
|
41
42
|
modulesDir?: string;
|
|
42
43
|
/**
|
|
@@ -61,8 +62,8 @@ export interface InlineConfig {
|
|
|
61
62
|
* - <span v-pre>`{{modeSuffix}}`</span>: A suffix based on the mode ('-dev' for development, '' for production)
|
|
62
63
|
* - <span v-pre>`{{command}}`</span>: The WXT command being run (e.g., 'build', 'serve')
|
|
63
64
|
*
|
|
64
|
-
* @example "{{browser}}-mv{{manifestVersion}}
|
|
65
|
-
* @default <span v-pre>`"{{browser}}-mv{{manifestVersion}}"`</span>
|
|
65
|
+
* @example "{{browser}}-mv{{manifestVersion}}"
|
|
66
|
+
* @default <span v-pre>`"{{browser}}-mv{{manifestVersion}}{{modeSuffix}}"`</span>
|
|
66
67
|
*/
|
|
67
68
|
outDirTemplate?: string;
|
|
68
69
|
/**
|
|
@@ -124,9 +125,13 @@ export interface InlineConfig {
|
|
|
124
125
|
*/
|
|
125
126
|
manifest?: UserManifest | Promise<UserManifest> | UserManifestFn;
|
|
126
127
|
/**
|
|
127
|
-
*
|
|
128
|
+
* Configure browser startup. Options set here can be overridden in a `web-ext.config.ts` file.
|
|
128
129
|
*/
|
|
129
|
-
|
|
130
|
+
webExt?: WebExtConfig;
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated Use `webExt` instead. Same option, just renamed.
|
|
133
|
+
*/
|
|
134
|
+
runner?: WebExtConfig;
|
|
130
135
|
zip?: {
|
|
131
136
|
/**
|
|
132
137
|
* Configure the filename output when zipping files.
|
|
@@ -247,25 +252,6 @@ export interface InlineConfig {
|
|
|
247
252
|
*/
|
|
248
253
|
compressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
249
254
|
};
|
|
250
|
-
/**
|
|
251
|
-
* @deprecated Use `hooks.build.manifestGenerated` to modify your manifest instead. This option
|
|
252
|
-
* will be removed in v1.0
|
|
253
|
-
*
|
|
254
|
-
* Transform the final manifest before it's written to the file system. Edit the `manifest`
|
|
255
|
-
* parameter directly, do not return a new object. Return values are ignored.
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* defineConfig({
|
|
259
|
-
* // Add a CSS-only content script.
|
|
260
|
-
* transformManifest(manifest) {
|
|
261
|
-
* manifest.content_scripts.push({
|
|
262
|
-
* matches: ["*://google.com/*"],
|
|
263
|
-
* css: ["content-scripts/some-example.css"],
|
|
264
|
-
* });
|
|
265
|
-
* }
|
|
266
|
-
* })
|
|
267
|
-
*/
|
|
268
|
-
transformManifest?: (manifest: Manifest.WebExtensionManifest) => void;
|
|
269
255
|
analysis?: {
|
|
270
256
|
/**
|
|
271
257
|
* Explicitly include bundle analysis when running `wxt build`. This can be overridden by the
|
|
@@ -323,30 +309,6 @@ export interface InlineConfig {
|
|
|
323
309
|
* }
|
|
324
310
|
*/
|
|
325
311
|
alias?: Record<string, string>;
|
|
326
|
-
/**
|
|
327
|
-
* Which extension API to use.
|
|
328
|
-
*
|
|
329
|
-
* - `"webextension-polyfill"`: Use `browser` and types from [`webextension-polyfill`](https://www.npmjs.com/package/webextension-polyfill).
|
|
330
|
-
* - `"chrome"`: Use the regular `chrome` (or `browser` for Firefox/Safari) globals provided by the browser. Types provided by [`@types/chrome`](https://www.npmjs.com/package/@types/chrome).
|
|
331
|
-
*
|
|
332
|
-
* @default "webextension-polyfill"
|
|
333
|
-
* @since 0.19.0
|
|
334
|
-
*/
|
|
335
|
-
extensionApi?: 'webextension-polyfill' | 'chrome';
|
|
336
|
-
/**
|
|
337
|
-
* @deprecated Will be removed in v0.20.0, please migrate to using `vite-node`, the new default.
|
|
338
|
-
*
|
|
339
|
-
* Method used to import entrypoint files during the build process to extract their options.
|
|
340
|
-
*
|
|
341
|
-
* - `"vite-node"` (default as of 0.19.0): Uses `vite-node` to import the entrypoints. Automatically includes vite config based on your wxt.config.ts file
|
|
342
|
-
* - `"jiti"`: Simplest and fastest, but doesn't allow using any imported variables outside the entrypoint's main function
|
|
343
|
-
*
|
|
344
|
-
* @see {@link https://wxt.dev/guide/go-further/entrypoint-importers.html|Entrypoint Importers}
|
|
345
|
-
*
|
|
346
|
-
* @default "vite-node"
|
|
347
|
-
* @since 0.19.0
|
|
348
|
-
*/
|
|
349
|
-
entrypointLoader?: 'vite-node' | 'jiti';
|
|
350
312
|
/**
|
|
351
313
|
* Experimental settings - use with caution.
|
|
352
314
|
*/
|
|
@@ -427,7 +389,7 @@ export interface WxtHooks {
|
|
|
427
389
|
'vite:devServer:extendConfig': (config: vite.InlineConfig) => HookResult;
|
|
428
390
|
}
|
|
429
391
|
export interface BuildOutput {
|
|
430
|
-
manifest: Manifest
|
|
392
|
+
manifest: Browser.runtime.Manifest;
|
|
431
393
|
publicAssets: OutputAsset[];
|
|
432
394
|
steps: BuildStepOutput[];
|
|
433
395
|
}
|
|
@@ -508,7 +470,7 @@ export interface WxtDevServer extends Omit<WxtBuilderServer, 'listen' | 'close'>
|
|
|
508
470
|
}
|
|
509
471
|
export interface ReloadContentScriptPayload {
|
|
510
472
|
registration?: BaseContentScriptEntrypointOptions['registration'];
|
|
511
|
-
contentScript: Omit<
|
|
473
|
+
contentScript: Omit<Browser.scripting.RegisteredContentScript, 'id'>;
|
|
512
474
|
}
|
|
513
475
|
export type TargetBrowser = string;
|
|
514
476
|
export type TargetManifestVersion = 2 | 3;
|
|
@@ -552,37 +514,37 @@ export interface BackgroundEntrypointOptions extends BaseEntrypointOptions {
|
|
|
552
514
|
type?: PerBrowserOption<'module'>;
|
|
553
515
|
}
|
|
554
516
|
export interface BaseContentScriptEntrypointOptions extends BaseEntrypointOptions {
|
|
555
|
-
matches?: PerBrowserOption<
|
|
517
|
+
matches?: PerBrowserOption<NonNullable<ManifestContentScript['matches']>>;
|
|
556
518
|
/**
|
|
557
519
|
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
558
520
|
* @default "documentIdle"
|
|
559
521
|
*/
|
|
560
|
-
runAt?: PerBrowserOption<
|
|
522
|
+
runAt?: PerBrowserOption<Browser.scripting.RegisteredContentScript['runAt']>;
|
|
561
523
|
/**
|
|
562
524
|
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
563
525
|
* @default false
|
|
564
526
|
*/
|
|
565
|
-
matchAboutBlank?: PerBrowserOption<
|
|
527
|
+
matchAboutBlank?: PerBrowserOption<ManifestContentScript['match_about_blank']>;
|
|
566
528
|
/**
|
|
567
529
|
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
568
530
|
* @default []
|
|
569
531
|
*/
|
|
570
|
-
excludeMatches?: PerBrowserOption<
|
|
532
|
+
excludeMatches?: PerBrowserOption<ManifestContentScript['exclude_matches']>;
|
|
571
533
|
/**
|
|
572
534
|
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
573
535
|
* @default []
|
|
574
536
|
*/
|
|
575
|
-
includeGlobs?: PerBrowserOption<
|
|
537
|
+
includeGlobs?: PerBrowserOption<ManifestContentScript['include_globs']>;
|
|
576
538
|
/**
|
|
577
539
|
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
578
540
|
* @default []
|
|
579
541
|
*/
|
|
580
|
-
excludeGlobs?: PerBrowserOption<
|
|
542
|
+
excludeGlobs?: PerBrowserOption<ManifestContentScript['exclude_globs']>;
|
|
581
543
|
/**
|
|
582
544
|
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
583
545
|
* @default false
|
|
584
546
|
*/
|
|
585
|
-
allFrames?: PerBrowserOption<
|
|
547
|
+
allFrames?: PerBrowserOption<ManifestContentScript['all_frames']>;
|
|
586
548
|
/**
|
|
587
549
|
* See https://developer.chrome.com/docs/extensions/mv3/content_scripts/
|
|
588
550
|
* @default false
|
|
@@ -784,15 +746,15 @@ export type ResolvedPerBrowserOptions<T, TOmitted extends keyof T = never> = {
|
|
|
784
746
|
* here, they are configured inline.
|
|
785
747
|
*/
|
|
786
748
|
export type UserManifest = {
|
|
787
|
-
[key in keyof
|
|
749
|
+
[key in keyof Browser.runtime.ManifestV3 as key extends 'action' | 'background' | 'chrome_url_overrides' | 'devtools_page' | 'manifest_version' | 'options_page' | 'options_ui' | 'permissions' | 'sandbox' | 'web_accessible_resources' ? never : key]?: Browser.runtime.ManifestV3[key];
|
|
788
750
|
} & {
|
|
789
|
-
action?:
|
|
751
|
+
action?: Browser.runtime.ManifestV3['action'] & {
|
|
790
752
|
browser_style?: boolean;
|
|
791
753
|
};
|
|
792
|
-
browser_action?:
|
|
754
|
+
browser_action?: Browser.runtime.ManifestV2['browser_action'] & {
|
|
793
755
|
browser_style?: boolean;
|
|
794
756
|
};
|
|
795
|
-
page_action?:
|
|
757
|
+
page_action?: Browser.runtime.ManifestV2['page_action'] & {
|
|
796
758
|
browser_style?: boolean;
|
|
797
759
|
};
|
|
798
760
|
browser_specific_settings?: {
|
|
@@ -811,8 +773,8 @@ export type UserManifest = {
|
|
|
811
773
|
strict_max_version?: string;
|
|
812
774
|
};
|
|
813
775
|
};
|
|
814
|
-
permissions?: (
|
|
815
|
-
web_accessible_resources?: string[] |
|
|
776
|
+
permissions?: (Browser.runtime.ManifestPermissions | (string & Record<never, never>))[];
|
|
777
|
+
web_accessible_resources?: string[] | Browser.runtime.ManifestV3['web_accessible_resources'];
|
|
816
778
|
};
|
|
817
779
|
export type UserManifestFn = (env: ConfigEnv) => UserManifest | Promise<UserManifest>;
|
|
818
780
|
export interface ConfigEnv {
|
|
@@ -838,9 +800,13 @@ export interface ConfigEnv {
|
|
|
838
800
|
}
|
|
839
801
|
export type WxtCommand = 'build' | 'serve';
|
|
840
802
|
/**
|
|
841
|
-
*
|
|
803
|
+
* @deprecated Use `WebExtConfig` instead.
|
|
842
804
|
*/
|
|
843
|
-
export
|
|
805
|
+
export type ExtensionRunnerConfig = WebExtConfig;
|
|
806
|
+
/**
|
|
807
|
+
* Options for how [`web-ext`](https://github.com/mozilla/web-ext) starts the browser.
|
|
808
|
+
*/
|
|
809
|
+
export interface WebExtConfig {
|
|
844
810
|
/**
|
|
845
811
|
* Whether or not to open the browser with the extension installed in dev mode.
|
|
846
812
|
*
|
|
@@ -1068,7 +1034,7 @@ export interface WxtHooks {
|
|
|
1068
1034
|
* @param wxt The configured WXT object
|
|
1069
1035
|
* @param manifest The manifest that was generated
|
|
1070
1036
|
*/
|
|
1071
|
-
'build:manifestGenerated': (wxt: Wxt, manifest: Manifest
|
|
1037
|
+
'build:manifestGenerated': (wxt: Wxt, manifest: Browser.runtime.Manifest) => HookResult;
|
|
1072
1038
|
/**
|
|
1073
1039
|
* Called once the names and paths of all entrypoints have been resolved.
|
|
1074
1040
|
* @param wxt The configured WXT object
|
|
@@ -1214,10 +1180,10 @@ export interface ResolvedConfig {
|
|
|
1214
1180
|
manifestVersion: TargetManifestVersion;
|
|
1215
1181
|
env: ConfigEnv;
|
|
1216
1182
|
logger: Logger;
|
|
1217
|
-
imports:
|
|
1183
|
+
imports: WxtResolvedUnimportOptions;
|
|
1218
1184
|
manifest: UserManifest;
|
|
1219
1185
|
fsCache: FsCache;
|
|
1220
|
-
runnerConfig: C12ResolvedConfig<
|
|
1186
|
+
runnerConfig: C12ResolvedConfig<WebExtConfig>;
|
|
1221
1187
|
zip: {
|
|
1222
1188
|
name?: string;
|
|
1223
1189
|
artifactTemplate: string;
|
|
@@ -1234,10 +1200,6 @@ export interface ResolvedConfig {
|
|
|
1234
1200
|
*/
|
|
1235
1201
|
zipSources: boolean;
|
|
1236
1202
|
};
|
|
1237
|
-
/**
|
|
1238
|
-
* @deprecated Use `build:manifestGenerated` hook instead.
|
|
1239
|
-
*/
|
|
1240
|
-
transformManifest?: (manifest: Manifest.WebExtensionManifest) => void;
|
|
1241
1203
|
analysis: {
|
|
1242
1204
|
enabled: boolean;
|
|
1243
1205
|
open: boolean;
|
|
@@ -1255,8 +1217,6 @@ export interface ResolvedConfig {
|
|
|
1255
1217
|
* Import aliases to absolute paths.
|
|
1256
1218
|
*/
|
|
1257
1219
|
alias: Record<string, string>;
|
|
1258
|
-
extensionApi: 'webextension-polyfill' | 'chrome';
|
|
1259
|
-
entrypointLoader: 'vite-node' | 'jiti';
|
|
1260
1220
|
experimental: {};
|
|
1261
1221
|
dev: {
|
|
1262
1222
|
/** Only defined during dev command */
|
|
@@ -1352,6 +1312,12 @@ export type WxtUnimportOptions = Partial<UnimportOptions> & {
|
|
|
1352
1312
|
eslintrc?: Eslintrc;
|
|
1353
1313
|
};
|
|
1354
1314
|
export type WxtResolvedUnimportOptions = Partial<UnimportOptions> & {
|
|
1315
|
+
/**
|
|
1316
|
+
* Set to `true` when the user disabled auto-imports. We still use unimport for the #imports module, but other features should be disabled.
|
|
1317
|
+
*
|
|
1318
|
+
* You don't need to check this value before modifying the auto-import options. Even if `disabled` is `true`, there's no harm in adding imports to the config - they'll just be ignored.
|
|
1319
|
+
*/
|
|
1320
|
+
disabled: boolean;
|
|
1355
1321
|
eslintrc: ResolvedEslintrc;
|
|
1356
1322
|
};
|
|
1357
1323
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/** @module wxt/utils/content-script-context */
|
|
2
|
+
import { ContentScriptDefinition } from '../types';
|
|
3
|
+
import { WxtLocationChangeEvent } from './internal/custom-events';
|
|
3
4
|
/**
|
|
4
5
|
* Implements [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
|
5
6
|
* Used to detect and stop content script code when the script is invalidated.
|
|
@@ -10,7 +11,7 @@ import { WxtLocationChangeEvent } from './custom-events';
|
|
|
10
11
|
* To create context for testing, you can use the class's constructor:
|
|
11
12
|
*
|
|
12
13
|
* ```ts
|
|
13
|
-
* import { ContentScriptContext } from 'wxt/
|
|
14
|
+
* import { ContentScriptContext } from 'wxt/utils/content-scripts-context';
|
|
14
15
|
*
|
|
15
16
|
* test("storage listener should be removed when context is invalidated", () => {
|
|
16
17
|
* const ctx = new ContentScriptContext('test');
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { browser } from "wxt/browser";
|
|
2
|
-
import { logger } from "
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { logger } from "../utils/internal/logger.mjs";
|
|
3
|
+
import {
|
|
4
|
+
getUniqueEventName
|
|
5
|
+
} from "./internal/custom-events.mjs";
|
|
6
|
+
import { createLocationWatcher } from "./internal/location-watcher.mjs";
|
|
5
7
|
export class ContentScriptContext {
|
|
6
8
|
constructor(contentScriptName, options) {
|
|
7
9
|
this.contentScriptName = contentScriptName;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ContentScriptContext } from '../content-script-context';
|
|
2
|
+
import type { ContentScriptUi, ContentScriptUiOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create a content script UI using an iframe.
|
|
5
|
+
*
|
|
6
|
+
* @see https://wxt.dev/guide/essentials/content-scripts.html#iframe
|
|
7
|
+
*/
|
|
8
|
+
export declare function createIframeUi<TMounted>(ctx: ContentScriptContext, options: IframeContentScriptUiOptions<TMounted>): IframeContentScriptUi<TMounted>;
|
|
9
|
+
export interface IframeContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
|
|
10
|
+
/**
|
|
11
|
+
* The iframe added to the DOM.
|
|
12
|
+
*/
|
|
13
|
+
iframe: HTMLIFrameElement;
|
|
14
|
+
/**
|
|
15
|
+
* A wrapper div that assists in positioning.
|
|
16
|
+
*/
|
|
17
|
+
wrapper: HTMLDivElement;
|
|
18
|
+
}
|
|
19
|
+
export type IframeContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
|
|
20
|
+
/**
|
|
21
|
+
* The path to the HTML page that will be shown in the iframe. This string is passed into
|
|
22
|
+
* `browser.runtime.getURL`.
|
|
23
|
+
*/
|
|
24
|
+
page: import('wxt/browser').HtmlPublicPath;
|
|
25
|
+
/**
|
|
26
|
+
* Callback executed when mounting the UI. Use this function to customize the iframe or wrapper
|
|
27
|
+
* element's appearance. It is called every time `ui.mount()` is called.
|
|
28
|
+
*
|
|
29
|
+
* Optionally return a value that can be accessed at `ui.mounted` or in the `onRemove` callback.
|
|
30
|
+
*/
|
|
31
|
+
onMount?: (wrapper: HTMLElement, iframe: HTMLIFrameElement) => TMounted;
|
|
32
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { browser } from "wxt/browser";
|
|
2
|
+
import { applyPosition, createMountFunctions, mountUi } from "./shared.mjs";
|
|
3
|
+
export function createIframeUi(ctx, options) {
|
|
4
|
+
const wrapper = document.createElement("div");
|
|
5
|
+
wrapper.setAttribute("data-wxt-iframe", "");
|
|
6
|
+
const iframe = document.createElement("iframe");
|
|
7
|
+
iframe.src = browser.runtime.getURL(options.page);
|
|
8
|
+
wrapper.appendChild(iframe);
|
|
9
|
+
let mounted = void 0;
|
|
10
|
+
const mount = () => {
|
|
11
|
+
applyPosition(wrapper, iframe, options);
|
|
12
|
+
mountUi(wrapper, options);
|
|
13
|
+
mounted = options.onMount?.(wrapper, iframe);
|
|
14
|
+
};
|
|
15
|
+
const remove = () => {
|
|
16
|
+
options.onRemove?.(mounted);
|
|
17
|
+
wrapper.remove();
|
|
18
|
+
mounted = void 0;
|
|
19
|
+
};
|
|
20
|
+
const mountFunctions = createMountFunctions({ mount, remove }, options);
|
|
21
|
+
ctx.onInvalidated(remove);
|
|
22
|
+
return {
|
|
23
|
+
get mounted() {
|
|
24
|
+
return mounted;
|
|
25
|
+
},
|
|
26
|
+
iframe,
|
|
27
|
+
wrapper,
|
|
28
|
+
...mountFunctions
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** @module wxt/utils/content-script-ui/integrated */
|
|
2
|
+
import { ContentScriptContext } from '../content-script-context';
|
|
3
|
+
import type { ContentScriptUi, ContentScriptUiOptions } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Create a content script UI without any isolation.
|
|
6
|
+
*
|
|
7
|
+
* @see https://wxt.dev/guide/essentials/content-scripts.html#integrated
|
|
8
|
+
*/
|
|
9
|
+
export declare function createIntegratedUi<TMounted>(ctx: ContentScriptContext, options: IntegratedContentScriptUiOptions<TMounted>): IntegratedContentScriptUi<TMounted>;
|
|
10
|
+
/**
|
|
11
|
+
* Shared types for the different `wxt/utils/content-script-ui/*` modules.
|
|
12
|
+
* @module wxt/utils/content-script-ui/types
|
|
13
|
+
*/
|
|
14
|
+
export interface IntegratedContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
|
|
15
|
+
/**
|
|
16
|
+
* A wrapper div that assists in positioning.
|
|
17
|
+
*/
|
|
18
|
+
wrapper: HTMLElement;
|
|
19
|
+
}
|
|
20
|
+
export type IntegratedContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
|
|
21
|
+
/**
|
|
22
|
+
* Tag used to create the wrapper element.
|
|
23
|
+
*
|
|
24
|
+
* @default "div"
|
|
25
|
+
*/
|
|
26
|
+
tag?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Callback executed when mounting the UI. This function should create and append the UI to the
|
|
29
|
+
* `wrapper` element. It is called every time `ui.mount()` is called.
|
|
30
|
+
*
|
|
31
|
+
* Optionally return a value that can be accessed at `ui.mounted` or in the `onRemove` callback.
|
|
32
|
+
*/
|
|
33
|
+
onMount: (wrapper: HTMLElement) => TMounted;
|
|
34
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { applyPosition, createMountFunctions, mountUi } from "./shared.mjs";
|
|
2
|
+
export function createIntegratedUi(ctx, options) {
|
|
3
|
+
const wrapper = document.createElement(options.tag || "div");
|
|
4
|
+
wrapper.setAttribute("data-wxt-integrated", "");
|
|
5
|
+
let mounted = void 0;
|
|
6
|
+
const mount = () => {
|
|
7
|
+
applyPosition(wrapper, void 0, options);
|
|
8
|
+
mountUi(wrapper, options);
|
|
9
|
+
mounted = options.onMount?.(wrapper);
|
|
10
|
+
};
|
|
11
|
+
const remove = () => {
|
|
12
|
+
options.onRemove?.(mounted);
|
|
13
|
+
wrapper.replaceChildren();
|
|
14
|
+
wrapper.remove();
|
|
15
|
+
mounted = void 0;
|
|
16
|
+
};
|
|
17
|
+
const mountFunctions = createMountFunctions(
|
|
18
|
+
{
|
|
19
|
+
mount,
|
|
20
|
+
remove
|
|
21
|
+
},
|
|
22
|
+
options
|
|
23
|
+
);
|
|
24
|
+
ctx.onInvalidated(remove);
|
|
25
|
+
return {
|
|
26
|
+
get mounted() {
|
|
27
|
+
return mounted;
|
|
28
|
+
},
|
|
29
|
+
wrapper,
|
|
30
|
+
...mountFunctions
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ContentScriptContext } from '../content-script-context';
|
|
2
|
+
import type { ContentScriptUi, ContentScriptUiOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create a content script UI inside a [`ShadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot).
|
|
5
|
+
*
|
|
6
|
+
* > This function is async because it has to load the CSS via a network call.
|
|
7
|
+
*
|
|
8
|
+
* @see https://wxt.dev/guide/essentials/content-scripts.html#shadow-root
|
|
9
|
+
*/
|
|
10
|
+
export declare function createShadowRootUi<TMounted>(ctx: ContentScriptContext, options: ShadowRootContentScriptUiOptions<TMounted>): Promise<ShadowRootContentScriptUi<TMounted>>;
|
|
11
|
+
export interface ShadowRootContentScriptUi<TMounted> extends ContentScriptUi<TMounted> {
|
|
12
|
+
/**
|
|
13
|
+
* The `HTMLElement` hosting the shadow root used to isolate the UI's styles. This is the element
|
|
14
|
+
* that get's added to the DOM. This element's style is not isolated from the webpage.
|
|
15
|
+
*/
|
|
16
|
+
shadowHost: HTMLElement;
|
|
17
|
+
/**
|
|
18
|
+
* The container element inside the `ShadowRoot` whose styles are isolated. The UI is mounted
|
|
19
|
+
* inside this `HTMLElement`.
|
|
20
|
+
*/
|
|
21
|
+
uiContainer: HTMLElement;
|
|
22
|
+
/**
|
|
23
|
+
* The shadow root performing the isolation.
|
|
24
|
+
*/
|
|
25
|
+
shadow: ShadowRoot;
|
|
26
|
+
}
|
|
27
|
+
export type ShadowRootContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMounted> & {
|
|
28
|
+
/**
|
|
29
|
+
* The name of the custom component used to host the ShadowRoot. Must be kebab-case.
|
|
30
|
+
*/
|
|
31
|
+
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* Custom CSS text to apply to the UI. If your content script imports/generates CSS and you've
|
|
34
|
+
* set `cssInjectionMode: "ui"`, the imported CSS will be included automatically. You do not need
|
|
35
|
+
* to pass those styles in here. This is for any additional styles not in the imported CSS.
|
|
36
|
+
*/
|
|
37
|
+
css?: string;
|
|
38
|
+
/**
|
|
39
|
+
* ShadowRoot's mode.
|
|
40
|
+
*
|
|
41
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/mode
|
|
42
|
+
* @default "open"
|
|
43
|
+
*/
|
|
44
|
+
mode?: 'open' | 'closed';
|
|
45
|
+
/**
|
|
46
|
+
* When enabled, `event.stopPropagation` will be called on events trying to bubble out of the
|
|
47
|
+
* shadow root.
|
|
48
|
+
*
|
|
49
|
+
* - Set to `true` to stop the propagation of a default set of events,
|
|
50
|
+
* `["keyup", "keydown", "keypress"]`
|
|
51
|
+
* - Set to an array of event names to stop the propagation of a custom list of events
|
|
52
|
+
*/
|
|
53
|
+
isolateEvents?: boolean | string[];
|
|
54
|
+
/**
|
|
55
|
+
* By default, WXT adds `all: initial` to the shadow root before the rest of
|
|
56
|
+
* your CSS. This resets any inheritable CSS styles that
|
|
57
|
+
* [normally pierce the Shadow DOM](https://open-wc.org/guides/knowledge/styling/styles-piercing-shadow-dom/).
|
|
58
|
+
*
|
|
59
|
+
* WXT resets everything but:
|
|
60
|
+
* - **`rem` Units**: they continue to scale based off the webpage's HTML `font-size`.
|
|
61
|
+
* - **CSS Variables/Custom Properties**: CSS variables defined outside the shadow root can be accessed inside it.
|
|
62
|
+
* - **`@font-face` Definitions**: Fonts defined outside the shadow root can be used inside it.
|
|
63
|
+
*
|
|
64
|
+
* To disable this behavior and inherit styles from the webpage, set `inheritStyles: true`.
|
|
65
|
+
*
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
inheritStyles?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Callback executed when mounting the UI. This function should create and append the UI to the
|
|
71
|
+
* `uiContainer` element. It is called every time `ui.mount()` is called.
|
|
72
|
+
*
|
|
73
|
+
* Optionally return a value that can be accessed at `ui.mounted` or in the `onRemove` callback.
|
|
74
|
+
*/
|
|
75
|
+
onMount: (uiContainer: HTMLElement, shadow: ShadowRoot, shadowHost: HTMLElement) => TMounted;
|
|
76
|
+
};
|