Skip to content
9 changes: 7 additions & 2 deletions shared-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ There has been increasing [developer](https://github.com/GoogleChromeLabs/privac

## [Maintaining a Session](https://github.com/GoogleChromeLabs/privacy-sandbox-dev-support/issues/124)

A developer embeds chat.com on two of their sites site-a.com and site-b.com. chat.com uses Shared Workers to maintain a user session.
A website, chat.example, offers a way to maintain active chat session between any sites the embed it using SharedWorkers.
Before storage partitioning this was possible, but after storage partitioning the when chat.example is embedded on different sites and instanciates a SharedWorker it would no longer be shared.
By prompting the user for permission via `document.requestStorageAccess({SharedWorker: true})` and then instanciating the SharedWorker via the returned handle the worker can be shared across partitioned third-party contexts.

## [Transfering an ArrayBuffer](https://groups.google.com/a/chromium.org/g/blink-dev/c/inRN8tI49O0/m/Q_TE0cw4AAAJ)

A developer embeds worker.com on two of their sites site-a.com and site-b.com. worker.com uses Shared Workers to transfer ArrayBuffers via postMessage.
A website, worker.example, wants to track and resume work in a first party context using SharedWorkers. `window.postMessage(...)` won't work as it would require inefficient cloning of significant data.
Before storage partitioning this was possible, but after storage partitioning the when worker.example is embedded in a third-party context and instanciates a SharedWorker it would no longer be shared with workers instanciated in a first-party context.
By prompting the user for permission via `document.requestStorageAccess({SharedWorker: true})` and then instanciating the SharedWorker via the returned handle the worker can be shared from a partitioned third-party context to a first-party context if the first-party worker is instanciated with the `sameSiteCookies: 'none'` option.
The worker shared this way won't gain access to `SameSite=Strict` cookies, which is important as `document.requestStorageAccess(...)` doesn't grant this either.

# Proposed Solution

Expand Down