wxt 0.16.11 → 0.17.0
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/{chunk-YH7RSTGT.js → chunk-FD7GO6WM.js} +1 -1
- package/dist/cli.js +11 -6
- package/dist/{index-h54vKikt.d.cts → index-Du5Xv5e8.d.cts} +7 -3
- package/dist/{index-h54vKikt.d.ts → index-Du5Xv5e8.d.ts} +7 -3
- package/dist/index.cjs +11 -6
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +11 -6
- package/dist/storage.cjs +49 -5
- package/dist/storage.d.cts +17 -8
- package/dist/storage.d.ts +17 -8
- package/dist/storage.js +48 -5
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/virtual/background-entrypoint.js +31 -14
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2181,7 +2181,7 @@ function getChunkSortWeight(filename) {
|
|
|
2181
2181
|
import pc4 from "picocolors";
|
|
2182
2182
|
|
|
2183
2183
|
// package.json
|
|
2184
|
-
var version = "0.
|
|
2184
|
+
var version = "0.17.0";
|
|
2185
2185
|
|
|
2186
2186
|
// src/core/utils/log/printHeader.ts
|
|
2187
2187
|
import { consola as consola2 } from "consola";
|
|
@@ -3204,8 +3204,8 @@ async function createServer(inlineConfig) {
|
|
|
3204
3204
|
transformHtml(url, html, originalUrl) {
|
|
3205
3205
|
return builderServer.transformHtml(url, html, originalUrl);
|
|
3206
3206
|
},
|
|
3207
|
-
reloadContentScript(
|
|
3208
|
-
server.ws.send("wxt:reload-content-script",
|
|
3207
|
+
reloadContentScript(payload) {
|
|
3208
|
+
server.ws.send("wxt:reload-content-script", payload);
|
|
3209
3209
|
},
|
|
3210
3210
|
reloadPage(path8) {
|
|
3211
3211
|
server.ws.send("wxt:reload-page", path8);
|
|
@@ -3306,9 +3306,14 @@ function reloadContentScripts(steps, server) {
|
|
|
3306
3306
|
const js = [getEntrypointBundlePath(entry, wxt.config.outDir, ".js")];
|
|
3307
3307
|
const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
|
|
3308
3308
|
const css = getContentScriptCssFiles([entry], cssMap);
|
|
3309
|
-
server.reloadContentScript(
|
|
3310
|
-
|
|
3311
|
-
|
|
3309
|
+
server.reloadContentScript({
|
|
3310
|
+
registration: entry.options.registration,
|
|
3311
|
+
contentScript: mapWxtOptionsToRegisteredContentScript(
|
|
3312
|
+
entry.options,
|
|
3313
|
+
js,
|
|
3314
|
+
css
|
|
3315
|
+
)
|
|
3316
|
+
});
|
|
3312
3317
|
});
|
|
3313
3318
|
} else {
|
|
3314
3319
|
server.reloadExtension();
|
|
@@ -471,14 +471,18 @@ interface WxtDevServer extends Omit<WxtBuilderServer, 'listen' | 'close'>, Serve
|
|
|
471
471
|
/**
|
|
472
472
|
* Tell the extension to restart a content script.
|
|
473
473
|
*
|
|
474
|
-
* @param
|
|
474
|
+
* @param payload Information about the content script to reload.
|
|
475
475
|
*/
|
|
476
|
-
reloadContentScript: (
|
|
476
|
+
reloadContentScript: (payload: ReloadContentScriptPayload) => void;
|
|
477
477
|
/**
|
|
478
478
|
* Grab the latest runner config and restart the browser.
|
|
479
479
|
*/
|
|
480
480
|
restartBrowser: () => void;
|
|
481
481
|
}
|
|
482
|
+
interface ReloadContentScriptPayload {
|
|
483
|
+
registration?: BaseContentScriptEntrypointOptions['registration'];
|
|
484
|
+
contentScript: Omit<Scripting.RegisteredContentScript, 'id'>;
|
|
485
|
+
}
|
|
482
486
|
type TargetBrowser = string;
|
|
483
487
|
type TargetManifestVersion = 2 | 3;
|
|
484
488
|
type UserConfig = Omit<InlineConfig, 'configFile'>;
|
|
@@ -1042,4 +1046,4 @@ type WxtResolvedUnimportOptions = Partial<UnimportOptions> & {
|
|
|
1042
1046
|
eslintrc: ResolvedEslintrc;
|
|
1043
1047
|
};
|
|
1044
1048
|
|
|
1045
|
-
export type {
|
|
1049
|
+
export type { EslintGlobalsPropValue as $, UserManifest as A, BuildOutput as B, ContentScriptEntrypoint as C, UserManifestFn as D, ExtensionRunnerConfig as E, ConfigEnv as F, GenericEntrypoint as G, WxtBuilder as H, InlineConfig as I, WxtBuilderServer as J, ServerInfo as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, HookResult as N, OutputFile as O, PopupEntrypointOptions as P, WxtHooks as Q, ReloadContentScriptPayload as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, Wxt as V, WxtDevServer as W, ResolvedConfig as X, FsCache as Y, ExtensionRunner as Z, VirtualEntrypointType as _, WxtViteConfig as a, Eslintrc as a0, ResolvedEslintrc as a1, WxtUnimportOptions as a2, WxtResolvedUnimportOptions as a3, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BackgroundEntrypointOptions as g, BaseContentScriptEntrypointOptions as h, IsolatedWorldContentScriptEntrypointOptions as i, OptionsEntrypointOptions as j, BaseEntrypoint as k, BackgroundEntrypoint as l, PopupEntrypoint as m, OptionsEntrypoint as n, SidepanelEntrypoint as o, Entrypoint as p, EntrypointGroup as q, OnContentScriptStopped as r, IsolatedWorldContentScriptDefinition as s, MainWorldContentScriptDefinition as t, ContentScriptDefinition as u, BackgroundDefinition as v, UnlistedScriptDefinition as w, PerBrowserOption as x, PerBrowserMap as y, ResolvedPerBrowserOptions as z };
|
|
@@ -471,14 +471,18 @@ interface WxtDevServer extends Omit<WxtBuilderServer, 'listen' | 'close'>, Serve
|
|
|
471
471
|
/**
|
|
472
472
|
* Tell the extension to restart a content script.
|
|
473
473
|
*
|
|
474
|
-
* @param
|
|
474
|
+
* @param payload Information about the content script to reload.
|
|
475
475
|
*/
|
|
476
|
-
reloadContentScript: (
|
|
476
|
+
reloadContentScript: (payload: ReloadContentScriptPayload) => void;
|
|
477
477
|
/**
|
|
478
478
|
* Grab the latest runner config and restart the browser.
|
|
479
479
|
*/
|
|
480
480
|
restartBrowser: () => void;
|
|
481
481
|
}
|
|
482
|
+
interface ReloadContentScriptPayload {
|
|
483
|
+
registration?: BaseContentScriptEntrypointOptions['registration'];
|
|
484
|
+
contentScript: Omit<Scripting.RegisteredContentScript, 'id'>;
|
|
485
|
+
}
|
|
482
486
|
type TargetBrowser = string;
|
|
483
487
|
type TargetManifestVersion = 2 | 3;
|
|
484
488
|
type UserConfig = Omit<InlineConfig, 'configFile'>;
|
|
@@ -1042,4 +1046,4 @@ type WxtResolvedUnimportOptions = Partial<UnimportOptions> & {
|
|
|
1042
1046
|
eslintrc: ResolvedEslintrc;
|
|
1043
1047
|
};
|
|
1044
1048
|
|
|
1045
|
-
export type {
|
|
1049
|
+
export type { EslintGlobalsPropValue as $, UserManifest as A, BuildOutput as B, ContentScriptEntrypoint as C, UserManifestFn as D, ExtensionRunnerConfig as E, ConfigEnv as F, GenericEntrypoint as G, WxtBuilder as H, InlineConfig as I, WxtBuilderServer as J, ServerInfo as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, HookResult as N, OutputFile as O, PopupEntrypointOptions as P, WxtHooks as Q, ReloadContentScriptPayload as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, Wxt as V, WxtDevServer as W, ResolvedConfig as X, FsCache as Y, ExtensionRunner as Z, VirtualEntrypointType as _, WxtViteConfig as a, Eslintrc as a0, ResolvedEslintrc as a1, WxtUnimportOptions as a2, WxtResolvedUnimportOptions as a3, OutputChunk as b, OutputAsset as c, BuildStepOutput as d, TargetManifestVersion as e, BaseEntrypointOptions as f, BackgroundEntrypointOptions as g, BaseContentScriptEntrypointOptions as h, IsolatedWorldContentScriptEntrypointOptions as i, OptionsEntrypointOptions as j, BaseEntrypoint as k, BackgroundEntrypoint as l, PopupEntrypoint as m, OptionsEntrypoint as n, SidepanelEntrypoint as o, Entrypoint as p, EntrypointGroup as q, OnContentScriptStopped as r, IsolatedWorldContentScriptDefinition as s, MainWorldContentScriptDefinition as t, ContentScriptDefinition as u, BackgroundDefinition as v, UnlistedScriptDefinition as w, PerBrowserOption as x, PerBrowserMap as y, ResolvedPerBrowserOptions as z };
|
package/dist/index.cjs
CHANGED
|
@@ -4608,7 +4608,7 @@ function getChunkSortWeight(filename) {
|
|
|
4608
4608
|
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
4609
4609
|
|
|
4610
4610
|
// package.json
|
|
4611
|
-
var version = "0.
|
|
4611
|
+
var version = "0.17.0";
|
|
4612
4612
|
|
|
4613
4613
|
// src/core/utils/log/printHeader.ts
|
|
4614
4614
|
var import_consola2 = require("consola");
|
|
@@ -5637,8 +5637,8 @@ async function createServer(inlineConfig) {
|
|
|
5637
5637
|
transformHtml(url2, html, originalUrl) {
|
|
5638
5638
|
return builderServer.transformHtml(url2, html, originalUrl);
|
|
5639
5639
|
},
|
|
5640
|
-
reloadContentScript(
|
|
5641
|
-
server.ws.send("wxt:reload-content-script",
|
|
5640
|
+
reloadContentScript(payload) {
|
|
5641
|
+
server.ws.send("wxt:reload-content-script", payload);
|
|
5642
5642
|
},
|
|
5643
5643
|
reloadPage(path11) {
|
|
5644
5644
|
server.ws.send("wxt:reload-page", path11);
|
|
@@ -5739,9 +5739,14 @@ function reloadContentScripts(steps, server) {
|
|
|
5739
5739
|
const js = [getEntrypointBundlePath(entry, wxt.config.outDir, ".js")];
|
|
5740
5740
|
const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
|
|
5741
5741
|
const css = getContentScriptCssFiles([entry], cssMap);
|
|
5742
|
-
server.reloadContentScript(
|
|
5743
|
-
|
|
5744
|
-
|
|
5742
|
+
server.reloadContentScript({
|
|
5743
|
+
registration: entry.options.registration,
|
|
5744
|
+
contentScript: mapWxtOptionsToRegisteredContentScript(
|
|
5745
|
+
entry.options,
|
|
5746
|
+
js,
|
|
5747
|
+
css
|
|
5748
|
+
)
|
|
5749
|
+
});
|
|
5745
5750
|
});
|
|
5746
5751
|
} else {
|
|
5747
5752
|
server.reloadExtension();
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-
|
|
2
|
-
export { v as BackgroundDefinition, l as BackgroundEntrypoint, g as BackgroundEntrypointOptions, h as BaseContentScriptEntrypointOptions, k as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput,
|
|
1
|
+
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-Du5Xv5e8.cjs';
|
|
2
|
+
export { v as BackgroundDefinition, l as BackgroundEntrypoint, g as BackgroundEntrypointOptions, h as BaseContentScriptEntrypointOptions, k as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, F as ConfigEnv, u as ContentScriptDefinition, C as ContentScriptEntrypoint, p as Entrypoint, q as EntrypointGroup, $ as EslintGlobalsPropValue, a0 as Eslintrc, Z as ExtensionRunner, Y as FsCache, G as GenericEntrypoint, N as HookResult, s as IsolatedWorldContentScriptDefinition, i as IsolatedWorldContentScriptEntrypointOptions, L as Logger, t as MainWorldContentScriptDefinition, M as MainWorldContentScriptEntrypointOptions, r as OnContentScriptStopped, n as OptionsEntrypoint, j as OptionsEntrypointOptions, c as OutputAsset, b as OutputChunk, O as OutputFile, y as PerBrowserMap, x as PerBrowserOption, m as PopupEntrypoint, P as PopupEntrypointOptions, R as ReloadContentScriptPayload, X as ResolvedConfig, a1 as ResolvedEslintrc, z as ResolvedPerBrowserOptions, K as ServerInfo, o as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, e as TargetManifestVersion, w as UnlistedScriptDefinition, A as UserManifest, D as UserManifestFn, _ as VirtualEntrypointType, V as Wxt, H as WxtBuilder, J as WxtBuilderServer, Q as WxtHooks, a3 as WxtResolvedUnimportOptions, a2 as WxtUnimportOptions, a as WxtViteConfig } from './index-Du5Xv5e8.cjs';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'webextension-polyfill';
|
|
5
5
|
import 'unimport';
|
|
@@ -64,6 +64,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
64
64
|
*/
|
|
65
65
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
66
66
|
|
|
67
|
-
var version = "0.
|
|
67
|
+
var version = "0.17.0";
|
|
68
68
|
|
|
69
69
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-
|
|
2
|
-
export { v as BackgroundDefinition, l as BackgroundEntrypoint, g as BackgroundEntrypointOptions, h as BaseContentScriptEntrypointOptions, k as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput,
|
|
1
|
+
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-Du5Xv5e8.js';
|
|
2
|
+
export { v as BackgroundDefinition, l as BackgroundEntrypoint, g as BackgroundEntrypointOptions, h as BaseContentScriptEntrypointOptions, k as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, F as ConfigEnv, u as ContentScriptDefinition, C as ContentScriptEntrypoint, p as Entrypoint, q as EntrypointGroup, $ as EslintGlobalsPropValue, a0 as Eslintrc, Z as ExtensionRunner, Y as FsCache, G as GenericEntrypoint, N as HookResult, s as IsolatedWorldContentScriptDefinition, i as IsolatedWorldContentScriptEntrypointOptions, L as Logger, t as MainWorldContentScriptDefinition, M as MainWorldContentScriptEntrypointOptions, r as OnContentScriptStopped, n as OptionsEntrypoint, j as OptionsEntrypointOptions, c as OutputAsset, b as OutputChunk, O as OutputFile, y as PerBrowserMap, x as PerBrowserOption, m as PopupEntrypoint, P as PopupEntrypointOptions, R as ReloadContentScriptPayload, X as ResolvedConfig, a1 as ResolvedEslintrc, z as ResolvedPerBrowserOptions, K as ServerInfo, o as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, e as TargetManifestVersion, w as UnlistedScriptDefinition, A as UserManifest, D as UserManifestFn, _ as VirtualEntrypointType, V as Wxt, H as WxtBuilder, J as WxtBuilderServer, Q as WxtHooks, a3 as WxtResolvedUnimportOptions, a2 as WxtUnimportOptions, a as WxtViteConfig } from './index-Du5Xv5e8.js';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'webextension-polyfill';
|
|
5
5
|
import 'unimport';
|
|
@@ -64,6 +64,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
64
64
|
*/
|
|
65
65
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
66
66
|
|
|
67
|
-
var version = "0.
|
|
67
|
+
var version = "0.17.0";
|
|
68
68
|
|
|
69
69
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
unnormalizePath,
|
|
18
18
|
version,
|
|
19
19
|
wxt
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-FD7GO6WM.js";
|
|
21
21
|
import "./chunk-VBXJIVYU.js";
|
|
22
22
|
|
|
23
23
|
// src/core/build.ts
|
|
@@ -268,8 +268,8 @@ async function createServer(inlineConfig) {
|
|
|
268
268
|
transformHtml(url, html, originalUrl) {
|
|
269
269
|
return builderServer.transformHtml(url, html, originalUrl);
|
|
270
270
|
},
|
|
271
|
-
reloadContentScript(
|
|
272
|
-
server.ws.send("wxt:reload-content-script",
|
|
271
|
+
reloadContentScript(payload) {
|
|
272
|
+
server.ws.send("wxt:reload-content-script", payload);
|
|
273
273
|
},
|
|
274
274
|
reloadPage(path3) {
|
|
275
275
|
server.ws.send("wxt:reload-page", path3);
|
|
@@ -370,9 +370,14 @@ function reloadContentScripts(steps, server) {
|
|
|
370
370
|
const js = [getEntrypointBundlePath(entry, wxt.config.outDir, ".js")];
|
|
371
371
|
const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
|
|
372
372
|
const css = getContentScriptCssFiles([entry], cssMap);
|
|
373
|
-
server.reloadContentScript(
|
|
374
|
-
|
|
375
|
-
|
|
373
|
+
server.reloadContentScript({
|
|
374
|
+
registration: entry.options.registration,
|
|
375
|
+
contentScript: mapWxtOptionsToRegisteredContentScript(
|
|
376
|
+
entry.options,
|
|
377
|
+
js,
|
|
378
|
+
css
|
|
379
|
+
)
|
|
380
|
+
});
|
|
376
381
|
});
|
|
377
382
|
} else {
|
|
378
383
|
server.reloadExtension();
|
package/dist/storage.cjs
CHANGED
|
@@ -40,6 +40,27 @@ var browser = import_webextension_polyfill.default;
|
|
|
40
40
|
|
|
41
41
|
// src/storage.ts
|
|
42
42
|
var import_lite = require("dequal/lite");
|
|
43
|
+
|
|
44
|
+
// src/sandbox/utils/logger.ts
|
|
45
|
+
var import_meta = {};
|
|
46
|
+
function print(method, ...args) {
|
|
47
|
+
if (import_meta.env.MODE === "production")
|
|
48
|
+
return;
|
|
49
|
+
if (typeof args[0] === "string") {
|
|
50
|
+
const message = args.shift();
|
|
51
|
+
method(`[wxt] ${message}`, ...args);
|
|
52
|
+
} else {
|
|
53
|
+
method("[wxt]", ...args);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
var logger = {
|
|
57
|
+
debug: (...args) => print(console.debug, ...args),
|
|
58
|
+
log: (...args) => print(console.log, ...args),
|
|
59
|
+
warn: (...args) => print(console.warn, ...args),
|
|
60
|
+
error: (...args) => print(console.error, ...args)
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/storage.ts
|
|
43
64
|
var storage = createStorage();
|
|
44
65
|
function createStorage() {
|
|
45
66
|
const drivers = {
|
|
@@ -250,7 +271,7 @@ function createStorage() {
|
|
|
250
271
|
"Storage item version cannot be less than 1. Initial versions should be set to 1, not 0."
|
|
251
272
|
);
|
|
252
273
|
}
|
|
253
|
-
const
|
|
274
|
+
const migrate = async () => {
|
|
254
275
|
const [value, meta] = await Promise.all([
|
|
255
276
|
// TODO: Optimize with getItems
|
|
256
277
|
getItem(driver, driverKey, void 0),
|
|
@@ -261,9 +282,12 @@ function createStorage() {
|
|
|
261
282
|
const currentVersion = meta.v ?? 1;
|
|
262
283
|
if (currentVersion > targetVersion) {
|
|
263
284
|
throw Error(
|
|
264
|
-
`
|
|
285
|
+
`Version downgrade detected (v${currentVersion} -> v${targetVersion}) for "${key}"`
|
|
265
286
|
);
|
|
266
287
|
}
|
|
288
|
+
logger.debug(
|
|
289
|
+
`Running storage migration for ${key}: v${currentVersion} -> v${targetVersion}`
|
|
290
|
+
);
|
|
267
291
|
const migrationsToRun = Array.from(
|
|
268
292
|
{ length: targetVersion - currentVersion },
|
|
269
293
|
(_, i) => currentVersion + i + 1
|
|
@@ -277,17 +301,37 @@ function createStorage() {
|
|
|
277
301
|
setItem(driver, driverKey, migratedValue),
|
|
278
302
|
setMeta(driver, driverKey, { v: targetVersion })
|
|
279
303
|
]);
|
|
304
|
+
logger.debug(
|
|
305
|
+
`Storage migration completed for ${key} v${targetVersion}`,
|
|
306
|
+
{ migratedValue }
|
|
307
|
+
);
|
|
280
308
|
};
|
|
281
|
-
|
|
309
|
+
browser.runtime.onInstalled.addListener(async ({ reason }) => {
|
|
310
|
+
if (reason !== "update")
|
|
311
|
+
return;
|
|
312
|
+
try {
|
|
313
|
+
await migrate();
|
|
314
|
+
} catch (err) {
|
|
315
|
+
logger.error(`Migration failed for ${key}`, err);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
const getDefaultValue = () => opts?.defaultValue ?? null;
|
|
282
319
|
return {
|
|
283
|
-
|
|
320
|
+
get defaultValue() {
|
|
321
|
+
return getDefaultValue();
|
|
322
|
+
},
|
|
284
323
|
getValue: () => getItem(driver, driverKey, opts),
|
|
285
324
|
getMeta: () => getMeta(driver, driverKey),
|
|
286
325
|
setValue: (value) => setItem(driver, driverKey, value),
|
|
287
326
|
setMeta: (properties) => setMeta(driver, driverKey, properties),
|
|
288
327
|
removeValue: (opts2) => removeItem(driver, driverKey, opts2),
|
|
289
328
|
removeMeta: (properties) => removeMeta(driver, driverKey, properties),
|
|
290
|
-
watch: (cb) => watch(
|
|
329
|
+
watch: (cb) => watch(
|
|
330
|
+
driver,
|
|
331
|
+
driverKey,
|
|
332
|
+
(newValue, oldValue) => cb(newValue ?? getDefaultValue(), oldValue ?? getDefaultValue())
|
|
333
|
+
),
|
|
334
|
+
migrate
|
|
291
335
|
};
|
|
292
336
|
}
|
|
293
337
|
};
|
package/dist/storage.d.cts
CHANGED
|
@@ -94,20 +94,21 @@ interface WxtStorage {
|
|
|
94
94
|
/**
|
|
95
95
|
* Watch for changes to a specific key in storage.
|
|
96
96
|
*/
|
|
97
|
-
watch<T>(key: string, cb: WatchCallback<T>): Unwatch;
|
|
97
|
+
watch<T>(key: string, cb: WatchCallback<T | null>): Unwatch;
|
|
98
98
|
/**
|
|
99
99
|
* Remove all watch listeners.
|
|
100
100
|
*/
|
|
101
101
|
unwatch(): void;
|
|
102
102
|
/**
|
|
103
|
-
* Define a
|
|
103
|
+
* Define a storage item with a default value, type, or versioning.
|
|
104
104
|
*
|
|
105
|
-
*
|
|
106
|
-
* export const installDate = storage.defineItem<number>("local:installDate");
|
|
105
|
+
* Read full docs: https://wxt.dev/guide/storage.html#defining-storage-items
|
|
107
106
|
*/
|
|
108
|
-
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string
|
|
107
|
+
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string): WxtStorageItem<TValue | null, TMetadata>;
|
|
108
|
+
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string, options: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
|
|
109
109
|
}
|
|
110
110
|
interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
111
|
+
defaultValue: TValue;
|
|
111
112
|
/**
|
|
112
113
|
* Get the latest value from storage.
|
|
113
114
|
*/
|
|
@@ -119,7 +120,7 @@ interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
|
119
120
|
/**
|
|
120
121
|
* Set the value in storage.
|
|
121
122
|
*/
|
|
122
|
-
setValue(value: TValue
|
|
123
|
+
setValue(value: TValue): Promise<void>;
|
|
123
124
|
/**
|
|
124
125
|
* Set metadata properties.
|
|
125
126
|
*/
|
|
@@ -136,6 +137,13 @@ interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
|
136
137
|
* Listen for changes to the value in storage.
|
|
137
138
|
*/
|
|
138
139
|
watch(cb: WatchCallback<TValue>): Unwatch;
|
|
140
|
+
/**
|
|
141
|
+
* If there are migrations defined on the storage item, migrate to the latest version.
|
|
142
|
+
*
|
|
143
|
+
* **This function is ran automatically whenever the extension updates**, so you don't have to call it
|
|
144
|
+
* manually.
|
|
145
|
+
*/
|
|
146
|
+
migrate(): Promise<void>;
|
|
139
147
|
}
|
|
140
148
|
interface GetItemOptions<T> {
|
|
141
149
|
/**
|
|
@@ -158,7 +166,8 @@ interface SnapshotOptions {
|
|
|
158
166
|
*/
|
|
159
167
|
excludeKeys?: string[];
|
|
160
168
|
}
|
|
161
|
-
interface WxtStorageItemOptions<T>
|
|
169
|
+
interface WxtStorageItemOptions<T> {
|
|
170
|
+
defaultValue: T;
|
|
162
171
|
/**
|
|
163
172
|
* Provide a version number for the storage item to enable migrations. When changing the version
|
|
164
173
|
* in the future, migration functions will be ran on application startup.
|
|
@@ -179,7 +188,7 @@ type NullablePartial<T> = {
|
|
|
179
188
|
/**
|
|
180
189
|
* Callback called when a value in storage is changed.
|
|
181
190
|
*/
|
|
182
|
-
type WatchCallback<T> = (newValue: T
|
|
191
|
+
type WatchCallback<T> = (newValue: T, oldValue: T) => void;
|
|
183
192
|
/**
|
|
184
193
|
* Call to remove a watch listener
|
|
185
194
|
*/
|
package/dist/storage.d.ts
CHANGED
|
@@ -94,20 +94,21 @@ interface WxtStorage {
|
|
|
94
94
|
/**
|
|
95
95
|
* Watch for changes to a specific key in storage.
|
|
96
96
|
*/
|
|
97
|
-
watch<T>(key: string, cb: WatchCallback<T>): Unwatch;
|
|
97
|
+
watch<T>(key: string, cb: WatchCallback<T | null>): Unwatch;
|
|
98
98
|
/**
|
|
99
99
|
* Remove all watch listeners.
|
|
100
100
|
*/
|
|
101
101
|
unwatch(): void;
|
|
102
102
|
/**
|
|
103
|
-
* Define a
|
|
103
|
+
* Define a storage item with a default value, type, or versioning.
|
|
104
104
|
*
|
|
105
|
-
*
|
|
106
|
-
* export const installDate = storage.defineItem<number>("local:installDate");
|
|
105
|
+
* Read full docs: https://wxt.dev/guide/storage.html#defining-storage-items
|
|
107
106
|
*/
|
|
108
|
-
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string
|
|
107
|
+
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string): WxtStorageItem<TValue | null, TMetadata>;
|
|
108
|
+
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: string, options: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
|
|
109
109
|
}
|
|
110
110
|
interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
111
|
+
defaultValue: TValue;
|
|
111
112
|
/**
|
|
112
113
|
* Get the latest value from storage.
|
|
113
114
|
*/
|
|
@@ -119,7 +120,7 @@ interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
|
119
120
|
/**
|
|
120
121
|
* Set the value in storage.
|
|
121
122
|
*/
|
|
122
|
-
setValue(value: TValue
|
|
123
|
+
setValue(value: TValue): Promise<void>;
|
|
123
124
|
/**
|
|
124
125
|
* Set metadata properties.
|
|
125
126
|
*/
|
|
@@ -136,6 +137,13 @@ interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
|
136
137
|
* Listen for changes to the value in storage.
|
|
137
138
|
*/
|
|
138
139
|
watch(cb: WatchCallback<TValue>): Unwatch;
|
|
140
|
+
/**
|
|
141
|
+
* If there are migrations defined on the storage item, migrate to the latest version.
|
|
142
|
+
*
|
|
143
|
+
* **This function is ran automatically whenever the extension updates**, so you don't have to call it
|
|
144
|
+
* manually.
|
|
145
|
+
*/
|
|
146
|
+
migrate(): Promise<void>;
|
|
139
147
|
}
|
|
140
148
|
interface GetItemOptions<T> {
|
|
141
149
|
/**
|
|
@@ -158,7 +166,8 @@ interface SnapshotOptions {
|
|
|
158
166
|
*/
|
|
159
167
|
excludeKeys?: string[];
|
|
160
168
|
}
|
|
161
|
-
interface WxtStorageItemOptions<T>
|
|
169
|
+
interface WxtStorageItemOptions<T> {
|
|
170
|
+
defaultValue: T;
|
|
162
171
|
/**
|
|
163
172
|
* Provide a version number for the storage item to enable migrations. When changing the version
|
|
164
173
|
* in the future, migration functions will be ran on application startup.
|
|
@@ -179,7 +188,7 @@ type NullablePartial<T> = {
|
|
|
179
188
|
/**
|
|
180
189
|
* Callback called when a value in storage is changed.
|
|
181
190
|
*/
|
|
182
|
-
type WatchCallback<T> = (newValue: T
|
|
191
|
+
type WatchCallback<T> = (newValue: T, oldValue: T) => void;
|
|
183
192
|
/**
|
|
184
193
|
* Call to remove a watch listener
|
|
185
194
|
*/
|
package/dist/storage.js
CHANGED
|
@@ -6,6 +6,26 @@ var browser = originalBrowser;
|
|
|
6
6
|
|
|
7
7
|
// src/storage.ts
|
|
8
8
|
import { dequal } from "dequal/lite";
|
|
9
|
+
|
|
10
|
+
// src/sandbox/utils/logger.ts
|
|
11
|
+
function print(method, ...args) {
|
|
12
|
+
if (import.meta.env.MODE === "production")
|
|
13
|
+
return;
|
|
14
|
+
if (typeof args[0] === "string") {
|
|
15
|
+
const message = args.shift();
|
|
16
|
+
method(`[wxt] ${message}`, ...args);
|
|
17
|
+
} else {
|
|
18
|
+
method("[wxt]", ...args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
var logger = {
|
|
22
|
+
debug: (...args) => print(console.debug, ...args),
|
|
23
|
+
log: (...args) => print(console.log, ...args),
|
|
24
|
+
warn: (...args) => print(console.warn, ...args),
|
|
25
|
+
error: (...args) => print(console.error, ...args)
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/storage.ts
|
|
9
29
|
var storage = createStorage();
|
|
10
30
|
function createStorage() {
|
|
11
31
|
const drivers = {
|
|
@@ -216,7 +236,7 @@ function createStorage() {
|
|
|
216
236
|
"Storage item version cannot be less than 1. Initial versions should be set to 1, not 0."
|
|
217
237
|
);
|
|
218
238
|
}
|
|
219
|
-
const
|
|
239
|
+
const migrate = async () => {
|
|
220
240
|
const [value, meta] = await Promise.all([
|
|
221
241
|
// TODO: Optimize with getItems
|
|
222
242
|
getItem(driver, driverKey, void 0),
|
|
@@ -227,9 +247,12 @@ function createStorage() {
|
|
|
227
247
|
const currentVersion = meta.v ?? 1;
|
|
228
248
|
if (currentVersion > targetVersion) {
|
|
229
249
|
throw Error(
|
|
230
|
-
`
|
|
250
|
+
`Version downgrade detected (v${currentVersion} -> v${targetVersion}) for "${key}"`
|
|
231
251
|
);
|
|
232
252
|
}
|
|
253
|
+
logger.debug(
|
|
254
|
+
`Running storage migration for ${key}: v${currentVersion} -> v${targetVersion}`
|
|
255
|
+
);
|
|
233
256
|
const migrationsToRun = Array.from(
|
|
234
257
|
{ length: targetVersion - currentVersion },
|
|
235
258
|
(_, i) => currentVersion + i + 1
|
|
@@ -243,17 +266,37 @@ function createStorage() {
|
|
|
243
266
|
setItem(driver, driverKey, migratedValue),
|
|
244
267
|
setMeta(driver, driverKey, { v: targetVersion })
|
|
245
268
|
]);
|
|
269
|
+
logger.debug(
|
|
270
|
+
`Storage migration completed for ${key} v${targetVersion}`,
|
|
271
|
+
{ migratedValue }
|
|
272
|
+
);
|
|
246
273
|
};
|
|
247
|
-
|
|
274
|
+
browser.runtime.onInstalled.addListener(async ({ reason }) => {
|
|
275
|
+
if (reason !== "update")
|
|
276
|
+
return;
|
|
277
|
+
try {
|
|
278
|
+
await migrate();
|
|
279
|
+
} catch (err) {
|
|
280
|
+
logger.error(`Migration failed for ${key}`, err);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
const getDefaultValue = () => opts?.defaultValue ?? null;
|
|
248
284
|
return {
|
|
249
|
-
|
|
285
|
+
get defaultValue() {
|
|
286
|
+
return getDefaultValue();
|
|
287
|
+
},
|
|
250
288
|
getValue: () => getItem(driver, driverKey, opts),
|
|
251
289
|
getMeta: () => getMeta(driver, driverKey),
|
|
252
290
|
setValue: (value) => setItem(driver, driverKey, value),
|
|
253
291
|
setMeta: (properties) => setMeta(driver, driverKey, properties),
|
|
254
292
|
removeValue: (opts2) => removeItem(driver, driverKey, opts2),
|
|
255
293
|
removeMeta: (properties) => removeMeta(driver, driverKey, properties),
|
|
256
|
-
watch: (cb) => watch(
|
|
294
|
+
watch: (cb) => watch(
|
|
295
|
+
driver,
|
|
296
|
+
driverKey,
|
|
297
|
+
(newValue, oldValue) => cb(newValue ?? getDefaultValue(), oldValue ?? getDefaultValue())
|
|
298
|
+
),
|
|
299
|
+
migrate
|
|
257
300
|
};
|
|
258
301
|
}
|
|
259
302
|
};
|
package/dist/testing.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
|
|
2
2
|
import * as vite from 'vite';
|
|
3
|
-
import { I as InlineConfig } from './index-
|
|
3
|
+
import { I as InlineConfig } from './index-Du5Xv5e8.cjs';
|
|
4
4
|
import 'webextension-polyfill';
|
|
5
5
|
import 'unimport';
|
|
6
6
|
import 'consola';
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
|
|
2
2
|
import * as vite from 'vite';
|
|
3
|
-
import { I as InlineConfig } from './index-
|
|
3
|
+
import { I as InlineConfig } from './index-Du5Xv5e8.js';
|
|
4
4
|
import 'webextension-polyfill';
|
|
5
5
|
import 'unimport';
|
|
6
6
|
import 'consola';
|
package/dist/testing.js
CHANGED
|
@@ -60,27 +60,44 @@ function keepServiceWorkerAlive() {
|
|
|
60
60
|
// src/virtual/utils/reload-content-scripts.ts
|
|
61
61
|
import { browser as browser2 } from "wxt/browser";
|
|
62
62
|
import { MatchPattern } from "wxt/sandbox";
|
|
63
|
-
function reloadContentScript(
|
|
63
|
+
function reloadContentScript(payload) {
|
|
64
64
|
const manifest = browser2.runtime.getManifest();
|
|
65
65
|
if (manifest.manifest_version == 2) {
|
|
66
|
-
void reloadContentScriptMv2(
|
|
66
|
+
void reloadContentScriptMv2(payload);
|
|
67
67
|
} else {
|
|
68
|
-
void reloadContentScriptMv3(
|
|
68
|
+
void reloadContentScriptMv3(payload);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
async function reloadContentScriptMv3(
|
|
72
|
-
|
|
71
|
+
async function reloadContentScriptMv3({
|
|
72
|
+
registration,
|
|
73
|
+
contentScript
|
|
74
|
+
}) {
|
|
75
|
+
if (registration === "runtime") {
|
|
76
|
+
await reloadRuntimeContentScriptMv3(contentScript);
|
|
77
|
+
} else {
|
|
78
|
+
await reloadRuntimeContentScriptMv3(contentScript);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function reloadRuntimeContentScriptMv3(contentScript) {
|
|
73
82
|
logger.log("Reloading content script:", contentScript);
|
|
74
83
|
const registered = await browser2.scripting.getRegisteredContentScripts();
|
|
75
84
|
logger.debug("Existing scripts:", registered);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
const matches = registered.filter((cs) => {
|
|
86
|
+
const hasJs = contentScript.js?.find((js) => cs.js?.includes(js));
|
|
87
|
+
const hasCss = contentScript.css?.find((css) => cs.css?.includes(css));
|
|
88
|
+
return hasJs || hasCss;
|
|
89
|
+
});
|
|
90
|
+
if (matches.length === 0) {
|
|
91
|
+
logger.log(
|
|
92
|
+
"Content script is not registered yet, nothing to reload",
|
|
93
|
+
contentScript
|
|
94
|
+
);
|
|
95
|
+
return;
|
|
83
96
|
}
|
|
97
|
+
await browser2.scripting.updateContentScripts(matches);
|
|
98
|
+
await reloadTabsForContentScript(contentScript);
|
|
99
|
+
}
|
|
100
|
+
async function reloadTabsForContentScript(contentScript) {
|
|
84
101
|
const allTabs = await browser2.tabs.query({});
|
|
85
102
|
const matchPatterns = contentScript.matches.map(
|
|
86
103
|
(match) => new MatchPattern(match)
|
|
@@ -93,7 +110,7 @@ async function reloadContentScriptMv3(contentScript) {
|
|
|
93
110
|
});
|
|
94
111
|
await Promise.all(matchingTabs.map((tab) => browser2.tabs.reload(tab.id)));
|
|
95
112
|
}
|
|
96
|
-
async function reloadContentScriptMv2(
|
|
113
|
+
async function reloadContentScriptMv2(_payload) {
|
|
97
114
|
throw Error("TODO: reloadContentScriptMv2");
|
|
98
115
|
}
|
|
99
116
|
|
|
@@ -126,7 +143,7 @@ try {
|
|
|
126
143
|
const res = definition.main();
|
|
127
144
|
if (res instanceof Promise) {
|
|
128
145
|
console.warn(
|
|
129
|
-
"The background's main() function return a promise, but it must be
|
|
146
|
+
"The background's main() function return a promise, but it must be synchronous"
|
|
130
147
|
);
|
|
131
148
|
}
|
|
132
149
|
} catch (err) {
|