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.
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.16.11";
2
+ var version = "0.17.0";
3
3
 
4
4
  // src/core/utils/paths.ts
5
5
  import systemPath from "node:path";
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.16.11";
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(contentScript) {
3208
- server.ws.send("wxt:reload-content-script", contentScript);
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
- mapWxtOptionsToRegisteredContentScript(entry.options, js, css)
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 contentScript The manifest definition for a content script
474
+ * @param payload Information about the content script to reload.
475
475
  */
476
- reloadContentScript: (contentScript: Omit<Scripting.RegisteredContentScript, 'id'>) => void;
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 { Eslintrc as $, UserManifestFn as A, BuildOutput as B, ContentScriptEntrypoint as C, ConfigEnv as D, ExtensionRunnerConfig as E, WxtBuilder as F, GenericEntrypoint as G, WxtBuilderServer as H, InlineConfig as I, ServerInfo as J, HookResult as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, WxtHooks as N, OutputFile as O, PopupEntrypointOptions as P, Wxt as Q, ResolvedPerBrowserOptions as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, ResolvedConfig as V, WxtDevServer as W, FsCache as X, ExtensionRunner as Y, VirtualEntrypointType as Z, EslintGlobalsPropValue as _, WxtViteConfig as a, ResolvedEslintrc as a0, WxtUnimportOptions as a1, WxtResolvedUnimportOptions as a2, 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, UserManifest as z };
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 contentScript The manifest definition for a content script
474
+ * @param payload Information about the content script to reload.
475
475
  */
476
- reloadContentScript: (contentScript: Omit<Scripting.RegisteredContentScript, 'id'>) => void;
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 { Eslintrc as $, UserManifestFn as A, BuildOutput as B, ContentScriptEntrypoint as C, ConfigEnv as D, ExtensionRunnerConfig as E, WxtBuilder as F, GenericEntrypoint as G, WxtBuilderServer as H, InlineConfig as I, ServerInfo as J, HookResult as K, Logger as L, MainWorldContentScriptEntrypointOptions as M, WxtHooks as N, OutputFile as O, PopupEntrypointOptions as P, Wxt as Q, ResolvedPerBrowserOptions as R, SidepanelEntrypointOptions as S, TargetBrowser as T, UserConfig as U, ResolvedConfig as V, WxtDevServer as W, FsCache as X, ExtensionRunner as Y, VirtualEntrypointType as Z, EslintGlobalsPropValue as _, WxtViteConfig as a, ResolvedEslintrc as a0, WxtUnimportOptions as a1, WxtResolvedUnimportOptions as a2, 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, UserManifest as z };
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.16.11";
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(contentScript) {
5641
- server.ws.send("wxt:reload-content-script", contentScript);
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
- mapWxtOptionsToRegisteredContentScript(entry.options, js, css)
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-h54vKikt.cjs';
2
- export { v as BackgroundDefinition, l as BackgroundEntrypoint, g as BackgroundEntrypointOptions, h as BaseContentScriptEntrypointOptions, k as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, D as ConfigEnv, u as ContentScriptDefinition, C as ContentScriptEntrypoint, p as Entrypoint, q as EntrypointGroup, _ as EslintGlobalsPropValue, $ as Eslintrc, Y as ExtensionRunner, X as FsCache, G as GenericEntrypoint, K 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, V as ResolvedConfig, a0 as ResolvedEslintrc, R as ResolvedPerBrowserOptions, J as ServerInfo, o as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, e as TargetManifestVersion, w as UnlistedScriptDefinition, z as UserManifest, A as UserManifestFn, Z as VirtualEntrypointType, Q as Wxt, F as WxtBuilder, H as WxtBuilderServer, N as WxtHooks, a2 as WxtResolvedUnimportOptions, a1 as WxtUnimportOptions, a as WxtViteConfig } from './index-h54vKikt.cjs';
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.16.11";
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-h54vKikt.js';
2
- export { v as BackgroundDefinition, l as BackgroundEntrypoint, g as BackgroundEntrypointOptions, h as BaseContentScriptEntrypointOptions, k as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, D as ConfigEnv, u as ContentScriptDefinition, C as ContentScriptEntrypoint, p as Entrypoint, q as EntrypointGroup, _ as EslintGlobalsPropValue, $ as Eslintrc, Y as ExtensionRunner, X as FsCache, G as GenericEntrypoint, K 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, V as ResolvedConfig, a0 as ResolvedEslintrc, R as ResolvedPerBrowserOptions, J as ServerInfo, o as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, e as TargetManifestVersion, w as UnlistedScriptDefinition, z as UserManifest, A as UserManifestFn, Z as VirtualEntrypointType, Q as Wxt, F as WxtBuilder, H as WxtBuilderServer, N as WxtHooks, a2 as WxtResolvedUnimportOptions, a1 as WxtUnimportOptions, a as WxtViteConfig } from './index-h54vKikt.js';
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.16.11";
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-YH7RSTGT.js";
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(contentScript) {
272
- server.ws.send("wxt:reload-content-script", contentScript);
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
- mapWxtOptionsToRegisteredContentScript(entry.options, js, css)
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 runMigrations = async () => {
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
- `[wxt/storage] Migration ignored for "${key}", version downgrade detected (${currentVersion} -> ${targetVersion})`
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
- let _migrationsCompleted = runMigrations();
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
- _migrationsCompleted,
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(driver, driverKey, cb)
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
  };
@@ -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 constant with utilities for reading/writing to a single value in storage.
103
+ * Define a storage item with a default value, type, or versioning.
104
104
  *
105
- * @example
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, options?: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
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 | null): Promise<void>;
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> extends GetItemOptions<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 | null, oldValue: T | null) => void;
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 constant with utilities for reading/writing to a single value in storage.
103
+ * Define a storage item with a default value, type, or versioning.
104
104
  *
105
- * @example
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, options?: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
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 | null): Promise<void>;
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> extends GetItemOptions<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 | null, oldValue: T | null) => void;
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 runMigrations = async () => {
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
- `[wxt/storage] Migration ignored for "${key}", version downgrade detected (${currentVersion} -> ${targetVersion})`
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
- let _migrationsCompleted = runMigrations();
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
- _migrationsCompleted,
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(driver, driverKey, cb)
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
  };
@@ -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-h54vKikt.cjs';
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-h54vKikt.js';
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
@@ -5,7 +5,7 @@ import {
5
5
  tsconfigPaths,
6
6
  unimport,
7
7
  webextensionPolyfillMock
8
- } from "./chunk-YH7RSTGT.js";
8
+ } from "./chunk-FD7GO6WM.js";
9
9
  import "./chunk-VBXJIVYU.js";
10
10
 
11
11
  // src/testing/fake-browser.ts
@@ -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(contentScript) {
63
+ function reloadContentScript(payload) {
64
64
  const manifest = browser2.runtime.getManifest();
65
65
  if (manifest.manifest_version == 2) {
66
- void reloadContentScriptMv2(contentScript);
66
+ void reloadContentScriptMv2(payload);
67
67
  } else {
68
- void reloadContentScriptMv3(contentScript);
68
+ void reloadContentScriptMv3(payload);
69
69
  }
70
70
  }
71
- async function reloadContentScriptMv3(contentScript) {
72
- const id = `wxt:${contentScript.js[0]}`;
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 existing = registered.find((cs) => cs.id === id);
77
- if (existing) {
78
- logger.debug("Updating content script", existing);
79
- await browser2.scripting.updateContentScripts([{ ...contentScript, id }]);
80
- } else {
81
- logger.debug("Registering new content script...");
82
- await browser2.scripting.registerContentScripts([{ ...contentScript, id }]);
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(contentScript) {
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 synchonous"
146
+ "The background's main() function return a promise, but it must be synchronous"
130
147
  );
131
148
  }
132
149
  } catch (err) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wxt",
3
3
  "type": "module",
4
- "version": "0.16.11",
4
+ "version": "0.17.0",
5
5
  "description": "Next gen framework for developing web extensions",
6
6
  "engines": {
7
7
  "node": ">=18",