@wxt-dev/storage 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +12 -5
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,6 +1,13 @@
1
1
  import { dequal } from 'dequal/lite';
2
2
  import { Mutex } from 'async-mutex';
3
3
 
4
+ const browser = (
5
+ // @ts-expect-error
6
+ globalThis.browser?.runtime?.id == null ? globalThis.chrome : (
7
+ // @ts-expect-error
8
+ globalThis.browser
9
+ )
10
+ );
4
11
  const storage = createStorage();
5
12
  function createStorage() {
6
13
  const drivers = {
@@ -152,7 +159,7 @@ function createStorage() {
152
159
  const resultsMap = {};
153
160
  await Promise.all(
154
161
  Object.entries(areaToDriverMetaKeysMap).map(async ([area, keys2]) => {
155
- const areaRes = await chrome.storage[area].get(
162
+ const areaRes = await browser.storage[area].get(
156
163
  keys2.map((key) => key.driverMetaKey)
157
164
  );
158
165
  keys2.forEach((key) => {
@@ -400,7 +407,7 @@ function createStorage() {
400
407
  }
401
408
  function createDriver(storageArea) {
402
409
  const getStorageArea = () => {
403
- if (chrome.runtime == null) {
410
+ if (browser.runtime == null) {
404
411
  throw Error(
405
412
  [
406
413
  "'wxt/storage' must be loaded in a web extension environment",
@@ -409,14 +416,14 @@ function createDriver(storageArea) {
409
416
  ].join("\n")
410
417
  );
411
418
  }
412
- if (chrome.storage == null) {
419
+ if (browser.storage == null) {
413
420
  throw Error(
414
421
  "You must add the 'storage' permission to your manifest to use 'wxt/storage'"
415
422
  );
416
423
  }
417
- const area = chrome.storage[storageArea];
424
+ const area = browser.storage[storageArea];
418
425
  if (area == null)
419
- throw Error(`"chrome.storage.${storageArea}" is undefined`);
426
+ throw Error(`"browser.storage.${storageArea}" is undefined`);
420
427
  return area;
421
428
  };
422
429
  const watchListeners = /* @__PURE__ */ new Set();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wxt-dev/storage",
3
3
  "description": "Web extension storage API provided by WXT, supports all browsers.",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",