Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Editorial review for Shared Storage API docs #30427

Merged
merged 134 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
09f74e0
Add first draft of Shared Storage API landing page
chrisdavidmills Jul 19, 2023
7a1984e
Add sharedstorage class
chrisdavidmills Jul 19, 2023
d4dced4
Lots more progress on documenting the interfaces
chrisdavidmills Jul 23, 2023
1928e17
final bits of content
chrisdavidmills Jul 24, 2023
ce9e2d1
Merge branch 'main' into shared-storage-api
chrisdavidmills Jul 24, 2023
c2fff8a
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Jul 25, 2023
702386f
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Jul 25, 2023
b3ee6b7
Update files/en-us/web/api/sharedstorage/index.md
chrisdavidmills Jul 25, 2023
a994416
Update files/en-us/web/api/sharedstorage/set/index.md
chrisdavidmills Jul 25, 2023
6a17946
small tweak
chrisdavidmills Jul 25, 2023
f2af72d
Merge branch 'main' into shared-storage-api
chrisdavidmills Jul 26, 2023
4dc61f8
Change Select URL gate name to Content Selection
chrisdavidmills Jul 26, 2023
3ac68d5
Merge branch 'shared-storage-api' of github.com:chrisdavidmills/conte…
chrisdavidmills Jul 26, 2023
8a3b64f
Add multiple operations example
chrisdavidmills Jul 26, 2023
11e3ee4
Fixes according to pythagoraskitty comments
chrisdavidmills Aug 3, 2023
82fc773
Merge branch 'main' into shared-storage-api
chrisdavidmills Aug 11, 2023
d6eab15
Update Content Selection to URL Selection
chrisdavidmills Aug 11, 2023
61420ea
Merge branch 'main' into shared-storage-api
chrisdavidmills Sep 28, 2023
62162fe
Fixes make for pythagoraskitty 2nd tech review
chrisdavidmills Sep 28, 2023
1fb0ac3
Merge branch 'main' into shared-storage-api
chrisdavidmills Oct 16, 2023
c983300
Add note and fix error on SharedStorage.delete() page
chrisdavidmills Oct 27, 2023
1de28cc
Merge branch 'main' into shared-storage-api
chrisdavidmills Nov 17, 2023
603ae92
Add enrollment information
chrisdavidmills Nov 17, 2023
c95f524
Update enrollment information in light of pythagoraskitty review
chrisdavidmills Nov 20, 2023
2356250
Remove enrollment exception criteria from register() as per review
chrisdavidmills Nov 21, 2023
502c2f3
Merge branch 'main' into shared-storage-api
chrisdavidmills Nov 21, 2023
a352835
Merge branch 'main' into shared-storage-api
chrisdavidmills Nov 24, 2023
8a96b38
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
f9d5c6a
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
e83356d
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
05a0f08
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
0db7f0c
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
e1ee6df
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
70c1076
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
d45ebe5
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
c930aa8
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
d87a6be
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
d9413a7
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
cc71a0f
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
30c1184
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
266fe4f
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
738a004
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 24, 2023
6f1dee5
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
fe636b8
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
9f6b144
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
0e3cb83
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
ae80133
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
bd584e0
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
d7ccaec
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
1757f6c
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
c506980
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
9aa897d
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
ff20c64
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
82cbd4c
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
47492c3
Update files/en-us/web/api/sharedstorageoperation/index.md
chrisdavidmills Nov 27, 2023
7bf8d00
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
30bfaf1
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
4eacc0a
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
5de5740
Update files/en-us/web/api/sharedstorage/index.md
chrisdavidmills Nov 27, 2023
1d48c0a
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills Nov 27, 2023
4d62d80
Update files/en-us/web/api/sharedstorageoperation/index.md
chrisdavidmills Nov 27, 2023
bf3e508
Update files/en-us/web/api/sharedstorageoperation/index.md
chrisdavidmills Nov 27, 2023
2817f85
Update files/en-us/web/api/sharedstorageoperation/index.md
chrisdavidmills Nov 27, 2023
a4983da
Update files/en-us/web/api/sharedstorageoperation/index.md
chrisdavidmills Nov 27, 2023
53fb5ee
Update files/en-us/web/api/sharedstoragerunoperation/index.md
chrisdavidmills Nov 27, 2023
6cd2e5c
Update files/en-us/web/api/sharedstoragerunoperation/index.md
chrisdavidmills Nov 27, 2023
ee9936f
Update files/en-us/web/api/sharedstoragerunoperation/index.md
chrisdavidmills Nov 27, 2023
eaf059e
Update files/en-us/web/api/sharedstoragerunoperation/index.md
chrisdavidmills Nov 27, 2023
39dd769
Update files/en-us/web/api/sharedstoragerunoperation/index.md
chrisdavidmills Nov 27, 2023
1c93bd2
Update files/en-us/web/api/sharedstorageselecturloperation/index.md
chrisdavidmills Nov 27, 2023
a7d1df7
Update files/en-us/web/api/sharedstorageselecturloperation/index.md
chrisdavidmills Nov 27, 2023
d914e7e
Update files/en-us/web/api/sharedstorageworklet/index.md
chrisdavidmills Nov 27, 2023
e87bf06
Update files/en-us/web/api/sharedstorageworklet/index.md
chrisdavidmills Nov 27, 2023
6104765
Update files/en-us/web/api/sharedstorageworklet/index.md
chrisdavidmills Nov 27, 2023
8fb2bf9
Update files/en-us/web/api/sharedstorageworkletglobalscope/index.md
chrisdavidmills Nov 27, 2023
d88f38e
Update files/en-us/web/api/sharedstorageworkletglobalscope/index.md
chrisdavidmills Nov 27, 2023
816dd97
Update files/en-us/web/api/windowsharedstorage/index.md
chrisdavidmills Nov 27, 2023
5b88f2a
Update files/en-us/web/api/windowsharedstorage/index.md
chrisdavidmills Nov 27, 2023
6ba9f00
Update files/en-us/web/api/windowsharedstorage/index.md
chrisdavidmills Nov 27, 2023
c333e19
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
95bd599
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
4e14990
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
94c0652
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
4170a01
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
2b0bd08
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
6fecae2
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
ca23288
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
a30ccb3
Update files/en-us/web/api/workletsharedstorage/index.md
chrisdavidmills Nov 27, 2023
bef38cf
Update files/en-us/web/api/sharedstorage/append/index.md
chrisdavidmills Nov 27, 2023
74e1d93
Update files/en-us/web/api/sharedstorage/append/index.md
chrisdavidmills Nov 27, 2023
8f0960e
Update files/en-us/web/api/sharedstorage/append/index.md
chrisdavidmills Nov 27, 2023
877ddbf
Update files/en-us/web/api/sharedstorage/append/index.md
chrisdavidmills Nov 27, 2023
897075e
Update files/en-us/web/api/sharedstorage/clear/index.md
chrisdavidmills Nov 27, 2023
8a6fd73
Update files/en-us/web/api/sharedstorage/clear/index.md
chrisdavidmills Nov 27, 2023
b4d1ee3
Update files/en-us/web/api/sharedstorage/set/index.md
chrisdavidmills Nov 27, 2023
ac0b456
Update files/en-us/web/api/sharedstorage/set/index.md
chrisdavidmills Nov 27, 2023
b385e80
Update files/en-us/web/api/sharedstorage/delete/index.md
chrisdavidmills Nov 27, 2023
a25574f
Update files/en-us/web/api/sharedstorage/delete/index.md
chrisdavidmills Nov 27, 2023
0e65098
Update files/en-us/web/api/sharedstoragerunoperation/run/index.md
chrisdavidmills Nov 27, 2023
39defd8
Update files/en-us/web/api/sharedstorageselecturloperation/run/index.md
chrisdavidmills Nov 27, 2023
f7ed28c
Update files/en-us/web/api/sharedstorageselecturloperation/run/index.md
chrisdavidmills Nov 27, 2023
20a67b9
Update files/en-us/web/api/workletsharedstorage/entries/index.md
chrisdavidmills Nov 27, 2023
97c3e5a
Update files/en-us/web/api/workletsharedstorage/get/index.md
chrisdavidmills Nov 27, 2023
9809d25
Update files/en-us/web/api/workletsharedstorage/get/index.md
chrisdavidmills Nov 27, 2023
9d3f35d
Update files/en-us/web/api/workletsharedstorage/get/index.md
chrisdavidmills Nov 27, 2023
bdb6013
Update files/en-us/web/api/workletsharedstorage/get/index.md
chrisdavidmills Nov 27, 2023
5fccce5
Update files/en-us/web/api/web_storage_api/index.md
chrisdavidmills Nov 27, 2023
46d9723
Update files/en-us/web/api/web_storage_api/index.md
chrisdavidmills Nov 27, 2023
a4cc0ed
Update files/en-us/web/api/windowsharedstorage/run/index.md
chrisdavidmills Nov 27, 2023
4ed5d85
Update files/en-us/web/api/windowsharedstorage/run/index.md
chrisdavidmills Nov 27, 2023
58af09b
Update files/en-us/web/api/windowsharedstorage/run/index.md
chrisdavidmills Nov 27, 2023
ece74e0
Update files/en-us/web/api/windowsharedstorage/run/index.md
chrisdavidmills Nov 28, 2023
f8e5a69
Update files/en-us/web/api/window/sharedstorage/index.md
chrisdavidmills Nov 28, 2023
fe798ed
Update files/en-us/web/api/windowsharedstorage/selecturl/index.md
chrisdavidmills Nov 28, 2023
f3be9ce
Update files/en-us/web/api/windowsharedstorage/selecturl/index.md
chrisdavidmills Nov 28, 2023
f1079db
Update files/en-us/web/api/windowsharedstorage/selecturl/index.md
chrisdavidmills Nov 28, 2023
5e61a4b
Update files/en-us/web/api/windowsharedstorage/worklet/index.md
chrisdavidmills Nov 28, 2023
63302e9
Update files/en-us/web/api/windowsharedstorage/worklet/index.md
chrisdavidmills Nov 28, 2023
6ab9fc0
Update files/en-us/web/api/sharedstorageworkletglobalscope/register/i…
chrisdavidmills Nov 28, 2023
0479d9e
Update files/en-us/web/api/sharedstorageselecturloperation/index.md
chrisdavidmills Nov 28, 2023
b2d8bc1
Update files/en-us/web/api/sharedstorageworkletglobalscope/register/i…
chrisdavidmills Nov 28, 2023
09718fc
Update files/en-us/web/api/sharedstorageworkletglobalscope/register/i…
chrisdavidmills Nov 28, 2023
bc402ba
Update files/en-us/web/api/sharedstorageworkletglobalscope/sharedstor…
chrisdavidmills Nov 28, 2023
631f8d6
Update files/en-us/web/api/workletsharedstorage/keys/index.md
chrisdavidmills Nov 28, 2023
180a4bd
Update files/en-us/web/api/workletsharedstorage/length/index.md
chrisdavidmills Nov 28, 2023
69e833a
Update files/en-us/web/api/workletsharedstorage/remainingbudget/index.md
chrisdavidmills Nov 28, 2023
a641b0c
Merge branch 'main' into shared-storage-api
chrisdavidmills Nov 28, 2023
990f0f4
Merge branch 'main' into shared-storage-api
chrisdavidmills Dec 4, 2023
d418343
Updates according to dipika comments
chrisdavidmills Dec 5, 2023
1d152f0
Shared_storage_API slug -> Shared_Storage_API
chrisdavidmills Dec 5, 2023
6993445
key/value -> key-value in shared storage api docs only
chrisdavidmills Dec 5, 2023
821100a
Responding to the remaining dipika comments
chrisdavidmills Dec 5, 2023
c5130b0
Merge branch 'main' into shared-storage-api
chrisdavidmills Dec 5, 2023
7481124
remove extra line
chrisdavidmills Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 267 additions & 0 deletions files/en-us/web/api/shared_storage_api/index.md

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions files/en-us/web/api/sharedstorage/append/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: "SharedStorage: append() method"
short-title: append()
slug: Web/API/SharedStorage/append
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.SharedStorage.append
---

{{APIRef("Shared Storage API")}}{{SeeCompatTable}}

The **`append()`** method of the {{domxref("SharedStorage")}} interface appends a string to the value of an existing key-value pair in the current origin's shared storage.

## Syntax

```js-nolint
append(key, value)
```

### Parameters

- `key`
- : A string representing the key of the key-value pair to which you want to append a value.
- `value`
- : A string that you want to append to the existing value of the key-value pair.

> **Note:** If the specified `key` isn't found in the shared storage, the `append()` operation is equivalent to {{domxref("SharedStorage.set", "set()")}}, that is, a new key-value pair with the specified `key` is added to the shared storage.

### Return value

A {{jsxref("Promise")}} that fulfills with `undefined`.

### Exceptions

- The `Promise` rejects with a {{jsxref("TypeError")}} if:
- The appended entry was not successfully stored in the database due to shared storage not being available (for example it is disabled using a browser setting).
- `key` and/or `value` exceed the browser-defined maximum length.
- The calling site does not have the Shared Storage API included in a successful [privacy sandbox enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment).
- In the case of {{domxref("WorkletSharedStorage")}}, the `Promise` rejects with a {{jsxref("TypeError")}} if the worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}.

> **Note:** In the case of {{domxref("WindowSharedStorage")}}, if the `append()` 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`.

## Examples

```js
window.sharedStorage
.append("integer-list", ",9")
.then(console.log("Value appended to integer list"));
dipikabh marked this conversation as resolved.
Show resolved Hide resolved
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Shared Storage API](/en-US/docs/Web/API/Shared_Storage_API)
54 changes: 54 additions & 0 deletions files/en-us/web/api/sharedstorage/clear/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "SharedStorage: clear() method"
short-title: clear()
slug: Web/API/SharedStorage/clear
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.SharedStorage.clear
---

{{APIRef("Shared Storage API")}}{{SeeCompatTable}}

The **`clear()`** method of the {{domxref("SharedStorage")}} interface clears the current origin's shared storage, removing all data from it.

## Syntax

```js-nolint
clear()
```

### Parameters

None.

### Return value

A {{jsxref("Promise")}} that fulfills with `undefined`.

### Exceptions

- The `Promise` rejects with a {{jsxref("TypeError")}} if:
- The database was not cleared successfully due to shared storage not being available (for example it is disabled using a browser setting).
- The calling site does not have the Shared Storage API included in a successful [privacy sandbox enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment).
- In the case of {{domxref("WorkletSharedStorage")}}, the `Promise` rejects with a {{jsxref("TypeError")}} if the worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}.

> **Note:** In the case of {{domxref("WindowSharedStorage")}}, if the `clear()` 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`.

## Examples

```js
window.sharedStorage.clear().then(console.log("Shared storage cleared"));
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Shared Storage API](/en-US/docs/Web/API/Shared_Storage_API)
61 changes: 61 additions & 0 deletions files/en-us/web/api/sharedstorage/delete/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: "SharedStorage: delete() method"
short-title: delete()
slug: Web/API/SharedStorage/delete
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.SharedStorage.delete
---

{{APIRef("Shared Storage API")}}{{SeeCompatTable}}

The **`delete()`** method of the {{domxref("SharedStorage")}} interface deletes an existing key-value pair from the current origin's shared storage.

## Syntax

```js-nolint
delete(key)
```

### Parameters

- `key`
- : A string representing the key of the key-value pair you want to delete.

### Return value

A {{jsxref("Promise")}} that fulfills with `undefined`.

### Exceptions

- The `Promise` rejects with a {{jsxref("TypeError")}} if:
- The database was not cleared successfully due to shared storage not being available (for example it is disabled using a browser setting).
- `key` exceeds the browser-defined maximum length.
- The calling site does not have the Shared Storage API included in a successful [privacy sandbox enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment).
- In the case of {{domxref("WorkletSharedStorage")}}, the `Promise` rejects with a {{jsxref("TypeError")}} if:
- The worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}.

> **Note:** If the key-value pair doesn't exist in the shared storage, no error is thrown — the operation still fulfills with `undefined`.

> **Note:** In the case of {{domxref("WindowSharedStorage")}}, if the `delete()` 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`.

## Examples

```js
window.sharedStorage
.delete("ab-testing-group")
.then(console.log("Value deleted"));
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Shared Storage API](/en-US/docs/Web/API/Shared_Storage_API)
51 changes: 51 additions & 0 deletions files/en-us/web/api/sharedstorage/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: SharedStorage
slug: Web/API/SharedStorage
page-type: web-api-interface
status:
- experimental
browser-compat: api.SharedStorage
---

{{APIRef("Shared Storage API")}}{{SeeCompatTable}}

The **`SharedStorage`** interface of the {{domxref("Shared Storage API", "Shared Storage API", "", "nocode")}} represents the shared storage for a particular origin, defining methods to write data to the shared storage.

`SharedStorage` is the base class for:

- {{domxref("WindowSharedStorage")}}, accessed via {{domxref("Window.sharedStorage")}}.
- {{domxref("WorkletSharedStorage")}}, accessed via {{domxref("SharedStorageWorkletGlobalScope.sharedStorage")}}.

{{InheritanceDiagram}}

## Instance methods

- {{domxref("SharedStorage.append", "append()")}} {{Experimental_Inline}}
- : Appends a string to the value of an existing key-value pair in the current origin's shared storage.
- {{domxref("SharedStorage.clear", "clear()")}} {{Experimental_Inline}}
- : Clears the current origin's shared storage, removing all data from it.
- {{domxref("SharedStorage.delete", "delete()")}} {{Experimental_Inline}}
- : Deletes an existing key-value pair from the current origin's shared storage.
- {{domxref("SharedStorage.set", "set()")}} {{Experimental_Inline}}
- : Stores a new key-value pair in the current origin's shared storage or updates an existing one.

## Examples

```js
window.sharedStorage
.set("ab-testing-group", "0")
.then(console.log("Value saved to shared storage"));
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("WindowSharedStorage")}}
- [Shared Storage API](/en-US/docs/Web/API/Shared_Storage_API)
67 changes: 67 additions & 0 deletions files/en-us/web/api/sharedstorage/set/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: "SharedStorage: set() method"
short-title: set()
slug: Web/API/SharedStorage/set
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.SharedStorage.set
---

{{APIRef("Shared Storage API")}}{{SeeCompatTable}}

The **`set()`** method of the {{domxref("SharedStorage")}} interface either stores a new key-value pair in the current origin's shared storage or updates an existing one.

## Syntax

```js-nolint
set(key, value)
set(key, value, options)
```

### Parameters

- `key`
- : A string representing the key in the key-value pair that you want to add or update.
- `value`
- : A string representing the value you want to add or update.
- `options` {{optional_inline}}
- : An options object containing the following properties:
- `ignoreIfPresent`
- : A 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.

### Return value

A {{jsxref("Promise")}} that fulfills with `undefined`.

### Exceptions

- The `Promise` rejects with a {{jsxref("TypeError")}} if:
- The created entry was not successfully stored in the database due to shared storage not being available (for example it is disabled using a browser setting).
- `key` and/or `value` exceed the browser-defined maximum length.
- The calling site does not have the Shared Storage API included in a successful [privacy sandbox enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment).
- In the case of {{domxref("WorkletSharedStorage")}}, the `Promise` rejects with a {{jsxref("TypeError")}} if the worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}.

> **Note:** In the case of {{domxref("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`.

## Examples

```js
window.sharedStorage
.set("ab-testing-group", "0", {
ignoreIfPresent: true,
})
.then(console.log("Set operation completed"));
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Shared Storage API](/en-US/docs/Web/API/Shared_Storage_API)
Loading