-
Notifications
You must be signed in to change notification settings - Fork 23.2k
feat: Technical review — Related website sets docs #30500
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
Closed
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
ae48e0a
Related website sets docs
chrisdavidmills 1d98073
Merge branch 'main' into related-website-sets
chrisdavidmills 7a00819
Rest of required content
chrisdavidmills 0992c1c
Merge branch 'main' into related-website-sets
chrisdavidmills 4d2b90f
Fix broken link
chrisdavidmills a57d3e4
Merge branch 'related-website-sets' of github.com:chrisdavidmills/con…
chrisdavidmills 47cfab3
Updated status for RWS
chrisdavidmills 09bdcb8
Merge branch 'main' into related-website-sets
chrisdavidmills e425412
Update files/en-us/web/api/document/requeststorageaccessfor/index.md
chrisdavidmills c2ff67d
Update files/en-us/web/api/document/requeststorageaccessfor/index.md
chrisdavidmills 3ad1838
Update files/en-us/web/api/storage_access_api/index.md
chrisdavidmills 9b695ce
Update files/en-us/web/api/storage_access_api/index.md
chrisdavidmills 2aeff35
Update files/en-us/web/api/storage_access_api/index.md
chrisdavidmills 05451cf
Update files/en-us/web/api/storage_access_api/index.md
chrisdavidmills ff9f8e0
Update files/en-us/web/privacy/index.md
chrisdavidmills 32e5f26
Update files/en-us/web/api/document/requeststorageaccessfor/index.md
chrisdavidmills f5e45ca
Merge branch 'main' into related-website-sets
chrisdavidmills 60457c1
Fix description list linter mess
chrisdavidmills dbdbea7
Fixes for cfredric tech review comments
chrisdavidmills 000f16c
Merge branch 'main' into related-website-sets
chrisdavidmills 2ea9508
address cfredric and tunetheweb feedback
chrisdavidmills 908b73e
Update files/en-us/web/api/storage_access_api/using/index.md
chrisdavidmills a083f0c
Update files/en-us/web/api/storage_access_api/using/index.md
chrisdavidmills 10d8db2
Update files/en-us/web/api/storage_access_api/using/index.md
chrisdavidmills 81c4df0
Update files/en-us/web/api/storage_access_api/using/index.md
chrisdavidmills e61854e
Update files/en-us/web/api/document/requeststorageaccessfor/index.md
chrisdavidmills b8afb84
Update files/en-us/web/api/document/requeststorageaccessfor/index.md
chrisdavidmills 281db89
Merge branch 'main' into related-website-sets
chrisdavidmills e3a0533
More tinkering with descriptions
chrisdavidmills d396b59
more small tweaks, link fix
chrisdavidmills c7fe6e1
Merge branch 'main' into related-website-sets
chrisdavidmills 8f703cc
Fix quote style - single to double
chrisdavidmills 46ead03
Merge branch 'related-website-sets' of github.com:chrisdavidmills/con…
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
This file contains hidden or 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 hidden or 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
120 changes: 120 additions & 0 deletions
120
files/en-us/web/api/document/requeststorageaccessfor/index.md
This file contains hidden or 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,120 @@ | ||
| --- | ||
| title: "Document: requestStorageAccessFor() method" | ||
| short-title: requestStorageAccessFor() | ||
| slug: Web/API/Document/requestStorageAccessFor | ||
| page-type: web-api-instance-method | ||
| status: | ||
| - experimental | ||
| browser-compat: api.Document.requestStorageAccessFor | ||
| --- | ||
|
|
||
| {{APIRef("Storage Access API")}}{{seecompattable}} | ||
|
|
||
| The **`requestStorageAccessFor()`** method of the {{domxref("Document")}} interface is a proposed extension to the Storage Access API that allows top-level sites to request third-party cookie access on behalf of embedded content originating from another site in the same [related website set](/en-US/docs/Web/API/Storage_Access_API/Related_website_sets). It returns a {{jsxref("Promise")}} that resolves if the access was granted, and rejects if access was denied. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```js-nolint | ||
| requestStorageAccessFor(requestedOrigin) | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| - `requestedOrigin` | ||
| - : A string representing the URL of the origin you are requesting third-party cookie access for. | ||
|
|
||
| ### Return value | ||
|
|
||
| A {{jsxref("Promise")}} that fulfills with `undefined` if the access to third-party cookies was granted, and rejects if access was denied. | ||
|
|
||
| `requestStorageAccessFor()` requests are automatically denied unless the embedded content is currently processing a user gesture such as a tap or click ({{Glossary("transient activation")}}), or unless permission was already granted previously. If permission was not previously granted, they need to be run inside a user gesture-based event handler. The user gesture behavior depends on the state of the promise: | ||
|
|
||
| - If the promise resolves (i.e. if permission was granted), then the user gesture has not been consumed, so the script can subsequently call APIs that require a user gesture. | ||
| - If the promise rejects (i.e. permission was not granted), then the user gesture has been consumed, so the script can't do anything that requires a gesture. This prevents scripts from calling `requestStorageAccessFor()` again if permission is denied. | ||
|
|
||
| ### Exceptions | ||
|
|
||
| - `InvalidStateError` {{domxref("DOMException")}} | ||
| - : Thrown if the current {{domxref("Document")}} is not yet active. | ||
| - `NotAllowedError` {{domxref("DOMException")}} | ||
| - : Thrown if: | ||
| - The document's window is not a [secure context](/en-US/docs/Web/Security/Secure_Contexts). | ||
| - The document is not the top-level document. | ||
| - The document has a `null` origin. | ||
| - The supplied `requestedOrigin` is [opaque](https://html.spec.whatwg.org/multipage/browsers.html#concept-origin-opaque). | ||
| - The top-level site and embedded site are not in the same [related website set](/en-US/docs/Web/API/Storage_Access_API/Related_website_sets). | ||
| - The embedding {{htmlelement("iframe")}} is sandboxed, and the `allow-storage-access-by-user-activation` token is not set. | ||
| - Usage is blocked by a {{httpheader("Permissions-Policy/storage-access", "storage-access")}} [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy). | ||
| - Usage is denied by the user agent's permission request to use the API. | ||
| - `TypeError` | ||
| - : Thrown if `requestedOrigin` is not a valid URL. | ||
|
|
||
| ## Description | ||
|
|
||
| `requestStorageAccessFor()` is intended to address challenges in adopting the Storage Access API on top-level sites that use cross-site images or scripts requiring cookies. It is relevant to user agents that by default block access to [third-party](/en-US/docs/Web/HTTP/Cookies#third-party_cookies), [unpartitioned](/en-US/docs/Web/API/Storage_Access_API#unpartitioned_versus_partitioned_cookies) cookies to improve privacy (e.g. to prevent tracking), and is a proposed extension of the [Storage Access API](/en-US/docs/Web/API/Storage_Access_API). | ||
|
|
||
| `requestStorageAccessFor()` can enable third-party cookie access for cross-site resources directly embedded into the top-level site that are unable to request their own storage access, for example via {{htmlelement("img")}} or {{htmlelement("script")}} elements. Cross-site content embedded in `<iframe>`s that has its own logic and resources and needs third-party cookie access should request its own storage access via {{domxref("Document.requestStorageAccess()")}}. | ||
|
|
||
| To check whether permission to access third-party cookies has already been granted via `requestStorageAccessFor()`, you can call {{domxref("Permissions.query()")}}, specifying the feature name `"top-level-storage-access"`. This is different to the feature name used for the regular {{domxref("Document.requestStorageAccess()")}} method, which is `"storage-access"`. | ||
|
|
||
| The `Permissions.query()` call must specify the embedded origin, for example: | ||
|
|
||
| ```js | ||
| navigator.permissions.query({ | ||
| name: "top-level-storage-access", | ||
| requestedOrigin: "https://www.example.com", | ||
| }); | ||
| ``` | ||
|
|
||
| > **Note:** Usage of this feature may be blocked by a {{httpheader("Permissions-Policy/storage-access", "storage-access")}} [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy) set on your server (the same one that controls the rest of the Storage Access API). In addition, the document must pass additional browser-specific checks such as allowlists, blocklists, on-device classification, user settings, or anti-[clickjacking](/en-US/docs/Glossary/Clickjacking) heuristics. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```js | ||
| function rSAFor() { | ||
| if ("requestStorageAccessFor" in document) { | ||
| document.requestStorageAccessFor("https://example.com").then( | ||
| (res) => { | ||
| // Use storage access | ||
| doThingsWithCookies(); | ||
| }, | ||
| (err) => { | ||
| // Handle errors | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| After a successful `requestStorageAccessFor()` call, cross-site requests will include cookies if they include [CORS](/en-US/docs/Web/HTTP/CORS) / [`crossorigin`](/en-US/docs/Web/HTML/Attributes/crossorigin), so sites may want to wait before triggering a request. Such requests must use the [`credentials: "include"`](/en-US/docs/Web/API/fetch#credentials) option and resources must include the `crossorigin="use-credentials"` attribute. | ||
|
|
||
| For example: | ||
|
|
||
| ```js | ||
| function checkCookie() { | ||
| fetch("https://example.com/getcookies.json", { | ||
| method: "GET", | ||
| credentials: "include", | ||
| }) | ||
| .then((response) => response.json()) | ||
| .then((json) => { | ||
| // Do something | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| > **Note:** See [Using the Storage Access API](/en-US/docs/Web/API/Storage_Access_API/Using) for a more complete example. | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - {{domxref("Document.hasStorageAccess()")}}, {{domxref("Document.requestStorageAccess()")}} | ||
| - [Using the Storage Access API](/en-US/docs/Web/API/Storage_Access_API/Using) | ||
| - [Introducing Storage Access API](https://webkit.org/blog/8124/introducing-storage-access-api/) (WebKit blog) | ||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.