-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09f74e0
commit 7a1984e
Showing
9 changed files
with
360 additions
and
10 deletions.
There are no files selected for viewing
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
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,67 @@ | ||
--- | ||
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. | ||
|
||
### 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. | ||
- If the worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}. | ||
- If the appended entry was not successfully stored in the database for some other reason. | ||
|
||
In both cases: | ||
|
||
- The `Promise` rejects with a {{jsxref("TypeError")}} if `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,53 @@ | ||
--- | ||
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("WorkletSharedStorage")}}, the `Promise` rejects with a {{jsxref("TypeError")}}: | ||
|
||
- If the worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}. | ||
- If the clearing operation was not successful for some reason. | ||
|
||
## 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,64 @@ | ||
--- | ||
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, or the delete operation was unsuccessful for some other reason. | ||
- 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 `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 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,73 @@ | ||
--- | ||
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 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 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 worklet module has not been added with {{domxref("Worklet.addModule", "SharedStorageWorklet.addModule()")}}. | ||
- If the created/updated entry was not successfully stored in the database for some other reason. | ||
|
||
In both cases: | ||
|
||
- The `Promise` rejects with a {{jsxref("TypeError")}} if `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) |
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
Oops, something went wrong.