Skip to main content
Chrome extensions cannot use localStorage reliably across all extension contexts. Use the chrome.storage API instead — it works in content scripts, the background service worker, the popup, and the options page.

Sync vs local storage

Choose the right storage area based on how the data should behave:
Use chrome.storage.sync for small settings like theme preferences or toggle states. Use chrome.storage.local for larger data like cached API responses or collected page data.

Write data

Call chrome.storage.sync.set or chrome.storage.local.set with an object of key-value pairs:

Read data

Pass an array of keys to retrieve:
Pass null to read everything in storage:

Remove and clear data

React to storage changes

Listen for changes across all extension contexts using chrome.storage.onChanged. This is useful for keeping the popup and content scripts in sync without manual polling:
Add this listener in your popup script to automatically refresh the UI when settings change — even if the change came from the options page.

Full example: save and load user preferences

Prompt Extensy to use storage

Include storage requirements in your extension prompt:
“Remember the user’s preferred language setting across sessions. Let them change it on the options page and apply it in the popup.”
Extensy will generate chrome.storage.sync.set and chrome.storage.sync.get calls in the appropriate files. If you need large-scale caching, specify that explicitly:
“Cache the last 50 search results in chrome.storage.local and clear them when the user clicks ‘Reset cache’.”
chrome.storage is asynchronous. Always read data inside the callback (or use await with the Promise-based API available in MV3) before acting on the result.