Gathering detailed insights and metrics for webext-options-sync
Gathering detailed insights and metrics for webext-options-sync
Gathering detailed insights and metrics for webext-options-sync
Gathering detailed insights and metrics for webext-options-sync
webext-options-sync-per-domain
Helps you manage and autosave your extension's options, separately for each additional permission.
webext-sync
Sync data between a web extension's background, popup, options and content scripts. Works cross-browser, with MV3 and MV2.
webext-autooptions
Store Extension Settings Easily
webext-options
webext-options-sync will soon be renamed to webext-options, but this package is currently empty
Helps you manage and autosave your extension's options.
npm install webext-options-sync
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
156 Stars
198 Commits
12 Forks
3 Watchers
1 Branches
11 Contributors
Updated on May 19, 2025
Latest Version
4.3.0
Package Id
webext-options-sync@4.3.0
Unpacked Size
29.14 kB
Size
9.00 kB
File Count
7
NPM Version
10.9.0
Node Version
23.1.0
Published on
Nov 17, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Helps you manage and autosave your extension's options.
Main features:
<form>
This also lets you very easily have separate options for each domain with the help of webext-options-sync-per-domain
.
You can download the standalone bundle and include it in your manifest.json
.
Or use npm
:
1npm install webext-options-sync
1import OptionsSync from 'webext-options-sync';
The browser-extension-template repo includes a complete setup with ES Modules, based on the advanced usage below.
This module requires the storage
permission in manifest.json
:
1{ 2 "name": "My Cool Extension", 3 "permissions": [ 4 "storage" 5 ] 6}
You can set and get your options from any context (background, content script, etc):
1/* global OptionsSync */ 2const optionsStorage = new OptionsSync(); 3 4await optionsStorage.set({showStars: 10}); 5 6const options = await optionsStorage.getAll(); 7// {showStars: 10}
Note: OptionsSync
relies on chrome.storage.sync
, so its limitations apply, both the size limit and the type of data stored (which must be compatible with JSON).
It's suggested to create an options-storage.js
file with your defaults and possible migrations, and import it where needed:
1/* global OptionsSync */
2window.optionsStorage = new OptionsSync({
3 defaults: {
4 colorString: 'green',
5 anyBooleans: true,
6 numbersAreFine: 9001
7 },
8
9 // List of functions that are called when the extension is updated
10 migrations: [
11 (savedOptions, currentDefaults) => {
12 // Perhaps it was renamed
13 if (savedOptions.colour) {
14 savedOptions.color = savedOptions.colour;
15 delete savedOptions.colour;
16 }
17 },
18
19 // Integrated utility that drops any properties that don't appear in the defaults
20 OptionsSync.migrations.removeUnused
21 ]
22});
Include this file as a background script: it's where the defaults
are set for the first time and where the migrations
are run. This example also includes it in the content script, if you need it there:
1{ 2 "background": { 3 "scripts": [ 4 "webext-options-sync.js", 5 "options-storage.js", 6 "background.js" 7 ] 8 }, 9 "content_scripts": [ 10 { 11 "matches": [ 12 "https://www.google.com/*", 13 ], 14 "js": [ 15 "webext-options-sync.js", 16 "options-storage.js", 17 "content.js" 18 ] 19 } 20 ] 21}
Then you can use it this way from the background
or content.js
:
1/* global optionsStorage */
2async function init () {
3 const {colorString} = await optionsStorage.getAll();
4 document.body.style.background = colorString;
5}
6
7init();
And also enable autosaving in your options page:
1<!-- Your options.html --> 2<form> 3 <label>Color: <input name="colorString"/></label><br> 4 <label>Show: <input type="checkbox" name="anyBooleans"/></label><br> 5 <label>Stars: <input name="numbersAreFine"/></label><br> 6</form> 7 8<script src="webext-options-sync.js"></script> 9<script src="options-storage.js"></script> 10<script src="options.js"></script>
1// Your options.js file
2/* global optionsStorage */
3
4optionsStorage.syncForm(document.querySelector('form'));
When using the syncForm
method, OptionsSync
will serialize the form using dom-form-serializer, which uses the name
attribute as key
for your options. Refer to its readme for more info on the structure of the data.
Any user changes to the form are automatically saved into chrome.storage.sync
after 300ms (debounced). It listens to input
events.
If your form fields have any validation attributes they will not be saved until they become valid.
Since autosave and validation is silent, you should inform the user of invalid fields, possibly via CSS by using the :invalid
selector:
1/* Style the element */ 2input:invalid { 3 color: red; 4 border: 1px solid red; 5} 6 7/* Or display a custom error message */ 8input:invalid ~ .error-message { 9 display: block; 10}
Returns an instance linked to the chosen storage. It will also run any migrations if it's called in the background.
Type: object
Optional. It should follow this format:
1{ 2 defaults: { // recommended 3 color: 'blue' 4 }, 5 migrations: [ // optional 6 savedOptions => { 7 if(savedOptions.oldStuff) { 8 delete savedOptions.oldStuff 9 } 10 } 11 ], 12}
Type: object
A map of default options as strings or booleans. The keys will have to match the options form fields' name
attributes.
Type: array
A list of functions to run in the background
when the extension is updated. Example:
1{ 2 migrations: [ 3 (options, defaults) => { 4 // Change the `options` 5 if(options.oldStuff) { 6 delete options.oldStuff 7 } 8 9 // No return needed 10 }, 11 12 // Integrated utility that drops any properties that don't appear in the defaults 13 OptionsSync.migrations.removeUnused 14 ], 15}
[!NOTE] The
options
argument will always include thedefaults
as well as any options that were saved before the update.
Type: string
Default: 'options'
The key used to store data in chrome.storage.sync
Type: boolean
Default: true
Whether info and warnings (on sync, updating form, etc.) should be logged to the console or not.
Type: 'local' | 'sync'
Default: sync
What storage area type to use (sync storage vs local storage). Sync storage is used by default.
Considerations for selecting which option to use:
browser_specific_settings.gecko.id
for the sync
storage to work locally.This will merge the existing options with the object provided.
Note: Any values specified in default
are not saved into the storage, to save space, but they will still appear when using getAll
. You just have to make sure to always specify the same defaults
object in every context (this happens automatically in the Advanced usage above.)
Type: object
Default: {}
Example: {color: red}
A map of default options as strings, booleans, numbers and anything accepted by dom-form-serializer’s deserialize
function.
This will override all the options stored with your options
.
This returns a Promise that will resolve with all the options.
Listens to changes in the storage and calls the callback when the options are changed. The callback is called with the new and old options.
Type: (newOptions: object, oldOptions: object) => void
Type: AbortSignal
If provided, the callback will be removed when the signal is aborted.
Any defaults or saved options will be loaded into the <form>
and any change will automatically be saved via chrome.storage.sync
. It also looks for any buttons with js-import
or js-export
classes that when clicked will allow the user to export and import the options to a JSON file.
options-sync:save-success
: Fired on the edited field when the form is saved.options-sync:save-error
: Fired on the edited field when the form is not saved due to an error. The error is passed as the detail
property.Saving can fail when the storage quota is exceeded for example. You should handle this case and display a message to the user.
Type: HTMLFormElement
, string
It's the <form>
that needs to be synchronized or a CSS selector (one element). The form fields' name
attributes will have to match the option names.
Removes any listeners added by syncForm
.
Opens the browser’s "save file" dialog to export options to a JSON file. If your form has a .js-export
element, this listener will be attached automatically.
Opens the browser’s file picker to import options from a previously-saved JSON file. If your form has a .js-import
element, this listener will be attached automatically.
webext-options-sync
to have different options for each domain your extension supports.No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More