This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The set() method of the SharedStorage interface either stores a new key-value pair in the current origin's shared storage or updates an existing one.
set(key, value) set(key, value, options)
keyA string representing the key in the key-value pair that you want to add or update.
valueA string representing the value you want to add or update.
options OptionalAn options object containing the following properties:
ignoreIfPresentA boolean value. The value true causes the set operation to abort if a key-value pair with the specified key already exists. The default value false causes the set operation to overwrite the previous value.
A Promise that fulfills with undefined.
Promise rejects with a TypeError if: key and/or value exceed the browser-defined maximum length.WorkletSharedStorage, the Promise rejects with a TypeError if the worklet module has not been added with SharedStorageWorklet.addModule().Note: In the case of WindowSharedStorage, if the set() operation doesn't successfully write to the database for a reason other than shared storage not being available, no error is thrown — the operation still fulfills with undefined.
window.sharedStorage
.set("ab-testing-group", "0", {
ignoreIfPresent: true,
})
.then(() => console.log("Set operation completed"));
| Specification |
|---|
| Shared Storage API> # dom-sharedstorage-set> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
set |
126 | 126 | No | 112 | No | 126 | No | 83 | No | 28.0 | 126 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SharedStorage/set