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

DO NOT MERGE: Technical review for Shared Storage API docs #28051

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 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
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
259 changes: 259 additions & 0 deletions files/en-us/web/api/shared_storage_api/index.md

Large diffs are not rendered by default.

61 changes: 61 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,61 @@
---
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 you want to append a string to.
- `value`
- : A string that you want to append to the existing value.

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

### Return value

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

### Exceptions

- 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, then it fails silently without rejecting.
- 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()")}}.
- In both cases, 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.

## Examples

```js
window.sharedStorage
.append("integer-list", ",9")
.then(console.log("Value appended to integer list"));
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Shared Storage API](/en-US/docs/Web/API/Shared_storage_API)
52 changes: 52 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,52 @@
---
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

- In the case of {{domxref("WindowSharedStorage")}}, if the `clear()` operation doesn't successfully clear the database for a reason other than shared storage not being available, then it fails silently without rejecting.
- 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()")}}.
- In both cases, 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).

## 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)
59 changes: 59 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,59 @@
---
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

- In the case of {{domxref("WindowSharedStorage")}}, if the key/value pair doesn't exist in the shared storage, the operation is aborted silently, without rejecting.
- In the case of {{domxref("WorkletSharedStorage")}}, the `Promise` rejects with a {{jsxref("TypeError")}} if:
- The key/value pair doesn't exist in the shared storage.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, delete is also aborted silently (i.e. resolves to undefined without error) for WorkletSharedStorage if the key doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, exceptions section updated appropriately in the next commit.

I've actually gone and updated all of these methods' exception sections in the same way — it felt a bit weird to have an exception listed that is actually a condition in which an exception is not thrown. So instead I've put such conditions in a note box below the list of exceptions, in each case.

- The worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}.
- In both cases, 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 `Promise` rejects with a {{jsxref("TypeError")}} if `key` exceeds the browser-defined maximum length.

## 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)
66 changes: 66 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,66 @@
---
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 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 of the key/value pair 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 that, if set to `true`, will cause the set operation to abort if a key/value pair with the specified `key` already exists. The default value, `false`, will cause the set operation to go ahead and overwrite the previous value, in such cases.

### Return value

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

### Exceptions

- 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, then it fails silently without rejecting.
- 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()")}}.
- In both cases, 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.

## 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