Shared Storage API enhancement (allow cross-origin script in addModule & align createWorklet)
- Category
- Offline / Storage
- Type
- New or changed feature
- Status
- No active development (Chrome No active development)
- Intent stage
- None
Summary
We now allow sharedStorage.worklet.addModule to load cross-origin script, while still using the invoking context's origin as the data partition origin for accessing shared storage data. We also align the behavior of sharedStorage.createWorklet, so that when it loads a cross-origin script, it also uses the invoking context's origin as the data partition origin by default (instead of using the script origin as it did when initially implemented). Finally, to preserve the ability to use the script's origin as the data partition origin, we introduce a new dataOrigin option for createWorklet. We have received feedback from developers stating they wanted to be able to host and run their worklet script on a separate origin from the origin that owns and writes their shared storage data. So we remove the same-origin restriction for addModule. Note that, when the worklet script is cross-origin to the invoking context, the invoking context's origin is used as the partition origin for accessing shared storage. To help avoid developer confusion in the long term, we align the default behavior of createWorklet to use the invoking context's origin instead of the script origin as its data partition origin. This is a breaking change, but current usage of createWorklet is low as it was introduced in M125. We also introduce a dataOrigin option that can be passed to use the previous behavior.
Motivation
We have heard from web developers who want to be able to use shared storage, but need to be able to host their worklet script from a CDN, while writing their shared storage data from their own origin's context. Third-party cookies were able to be shared across multiple origins on the same site, whereas the initial implementation of shared storage did not have any mechanism to account for hosting a worklet script on an origin that is cross-origin to the origin owning the shared storage data to be processed by the script. These API enhancements solve this use case. Note that the shared storage data itself is not shared between the two origins, however, as the worklet script faces the same output restrictions originally placed on shared storage worklets.
Standards & signals
- Specification: https://github.com/WICG/shared-storage/pull/161
- Firefox: No signal
- Safari: No signal
- Web developers: No signals
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=shared-storage-api-enhancement-allow-cross-origin-script-in-addmodule-align-createworklet
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+Shared%20Storage%20API%20enhancement%20(allow%20cross-origin%20script%20in%20addModule%20%26%20align%20createWorklet)
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=Shared%20Storage%20API%20enhancement%20(allow%20cross-origin%20script%20in%20addModule%20%26%20align%20createWorklet)
- Baseline status: https://webstatus.dev/?q=Shared%20Storage%20API%20enhancement%20(allow%20cross-origin%20script%20in%20addModule%20%26%20align%20createWorklet)
Explainers: https://github.com/WICG/shared-storage/blob/main/README.md