@webext-core/storagedefineExtensionStoragefunction defineExtensionStorage<TSchema extends AnySchema = AnySchema>(
storage: Storage.StorageArea,
): ExtensionStorage<TSchema> {
// ...
}
Create a storage instance with an optional schema, TSchema, for type safety.
storage: Storage.StorageAreaBrowser.storage.local, Browser.storage.sync, or Browser.storage.managed.import browser from 'webextension-polyfill';
interface Schema {
installDate: number;
}
const extensionStorage = defineExtensionStorage<Schema>(browser.storage.local);
const date = await extensionStorage.getItem("installDate");
ExtensionStorageinterface ExtensionStorage<TSchema extends AnySchema> {
clear(): Promise<void>;
getItem<TKey extends keyof TSchema>(
key: TKey,
): Promise<Required<TSchema>[TKey] | null>;
setItem<TKey extends keyof TSchema>(
key: TKey,
value: TSchema[TKey],
): Promise<void>;
removeItem<TKey extends keyof TSchema>(key: TKey): Promise<void>;
onChange<TKey extends keyof TSchema>(
key: TKey,
cb: OnChangeCallback<TSchema, TKey>,
): RemoveListenerCallback;
}
This is the interface for the storage objects exported from the package. It is similar to localStorage, except for a few differences:
localExtStorageconst localExtStorage: ExtensionStorage<AnySchema>;
An implementation of ExtensionStorage based on the browser.storage.local storage area.
managedExtStorageconst managedExtStorage: ExtensionStorage<AnySchema>;
An implementation of ExtensionStorage based on the browser.storage.managed storage area.
sessionExtStorageconst sessionExtStorage: ExtensionStorage<AnySchema>;
An implementation of ExtensionStorage based on the browser.storage.local storage area.
syncExtStorageconst syncExtStorage: ExtensionStorage<AnySchema>;
An implementation of ExtensionStorage based on the browser.storage.sync storage area.
API reference generated by docs/generate-api-references.ts