WXT Storage

With WXT

This module is built-in to WXT, so you don't need to install anything. But must enable storage permissions

import { storage } from '#imports';

wxt.config.ts

export default defineConfig({
  manifest: {
    permissions: ['storage'],
  },
});

All storage keys must be prefixed by their storage area: local:, session:, sync:, or managed:.

await storage.getItem<number>('local:installDate');
await storage.watch<number>(
  'local:installDate',
  (newInstallDate, oldInstallDate) => {
    // ...
  },
);
await storage.getMeta<{ v: number }>('local:installDate');

Define Storage Items

  • Define an items type, default value, and more in a single place

  • Use that helper function instead of storage.

// utils/storage.ts

Last updated