Installation
MV2 MV3 Chrome Firefox Safari
Overview
@webext-core/storage
provides a type-safe, localStorage
-like API for interacting with extension storage.
const { key: value } = await browser.storage.local.get('key');
// VS
const value = await localExtStorage.getItem('key');
Requires the
storage
permission.Installation
NPM
pnpm i @webext-core/storage
import { localExtStorage } from '@webext-core/storage';
const value = await localExtStorage.getItem('key');
await localExtStorage.setItem('key', 123);
CDN
curl -o storage.js https://cdn.jsdelivr.net/npm/@webext-core/storage/lib/index.global.js
<script src="/storage.js"></script>
<script>
const { localExtStorage } = webExtCoreStorage;
const value = await localExtStorage.getItem('key');
await localExtStorage.setItem('key', 123);
</script>
Differences with localStorage
and browser.storage
@webext-core/storage | localStorage | browser.storage | |
---|---|---|---|
Set value to undefined removes it? | ✅ | ✅ | ❌ |
Returns null for missing values? | ✅ | ✅ | ❌ |
Stores non-string values? | ✅ | ❌ | ✅ |
Async? | ✅ | ❌ | ✅ |
Otherwise, the storage behaves the same as localStorage
/ sessionStorage
.