-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
Closed
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 7a1984e
Add sharedstorage class
chrisdavidmills d4dced4
Lots more progress on documenting the interfaces
chrisdavidmills 1928e17
final bits of content
chrisdavidmills ce9e2d1
Merge branch 'main' into shared-storage-api
chrisdavidmills c2fff8a
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills 702386f
Update files/en-us/web/api/shared_storage_api/index.md
chrisdavidmills b3ee6b7
Update files/en-us/web/api/sharedstorage/index.md
chrisdavidmills a994416
Update files/en-us/web/api/sharedstorage/set/index.md
chrisdavidmills 6a17946
small tweak
chrisdavidmills f2af72d
Merge branch 'main' into shared-storage-api
chrisdavidmills 4dc61f8
Change Select URL gate name to Content Selection
chrisdavidmills 3ac68d5
Merge branch 'shared-storage-api' of github.com:chrisdavidmills/conte…
chrisdavidmills 8a3b64f
Add multiple operations example
chrisdavidmills 11e3ee4
Fixes according to pythagoraskitty comments
chrisdavidmills 82fc773
Merge branch 'main' into shared-storage-api
chrisdavidmills d6eab15
Update Content Selection to URL Selection
chrisdavidmills 61420ea
Merge branch 'main' into shared-storage-api
chrisdavidmills 62162fe
Fixes make for pythagoraskitty 2nd tech review
chrisdavidmills 1fb0ac3
Merge branch 'main' into shared-storage-api
chrisdavidmills c983300
Add note and fix error on SharedStorage.delete() page
chrisdavidmills 1de28cc
Merge branch 'main' into shared-storage-api
chrisdavidmills 603ae92
Add enrollment information
chrisdavidmills c95f524
Update enrollment information in light of pythagoraskitty review
chrisdavidmills 2356250
Remove enrollment exception criteria from register() as per review
chrisdavidmills 502c2f3
Merge branch 'main' into shared-storage-api
chrisdavidmills File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.