How to Configure Partitioned Cookies (CHIPS) in Service Workers in Google Chrome

As third-party cookie phaseouts accelerate across the web, cross-site embedded widgets—such as payment iframes, customer support chat modules, and enterprise analytics dashboards—face severe state persistence barriers. Cookies Having Independent Partitioned State (CHIPS) resolves this challenge by partitioning cookies by top-level site using the Partitioned attribute. However, modern Single Page Applications (SPAs) and Progressive Web Apps (PWAs) frequently coordinate network traffic through Service Workers, where unpartitioned cookie assumptions can break API authentication. In Google Chrome, configuring partitioned cookie propagation within Service Workers ensures compliant, privacy-preserving session management.

Understanding CHIPS and the Partitioned Cookie Attribute

CHIPS introduces a dedicated cookie attribute that binds cookies to the top-level origin where the frame is embedded:

  • Set-Cookie: __Host-sid=xyz123; Secure; Path=/; SameSite=None; Partitioned;
  • Double-Keyed Partitioning: A partitioned cookie stored when app.example.com is embedded inside site-a.com cannot be read when app.example.com is embedded inside site-b.com or visited directly.
  • Service Worker Partitioning: In Chromium, Service Worker registrations originating from partitioned iframes are also partitioned, ensuring that worker-mediated fetch() requests automatically inherit matching partitioned cookies.

Configuring Web Server Headers for CHIPS Delivery

Configure your API or authentication service to append the Partitioned directive to cross-site session cookies:

# Nginx server configuration for partitioned API cookies
location /api/v1/session {
    add_header Set-Cookie "__Host-client-session=token_abc789; Secure; Path=/; SameSite=None; Partitioned; HttpOnly" always;
    proxy_pass http://127.0.0.1:4000;
}

# Apache HTTP Server (.htaccess / virtual host)
Header always edit Set-Cookie "^(.*)$" "$1; Partitioned"

Note that the cookie must use the __Host- prefix (requiring Secure, Path=/, and omitting domain attributes) to satisfy strict CHIPS requirements.

Managing Partitioned Cookies in Service Worker Fetch Handlers

When intercepting network requests inside a Service Worker, ensure credentials are explicitly forwarded:

// service-worker.js
self.addEventListener('fetch', (event) => {
    const url = new URL(event.request.url);

    if (url.pathname.startsWith('/api/')) {
        event.respondWith((async () => {
            // Forward request with partitioned ambient credentials included
            const modifiedRequest = new Request(event.request, {
                credentials: 'include'
            });
            return await fetch(modifiedRequest);
        })());
    }
});

Auditing CHIPS Partitioning in Chrome DevTools

To inspect and audit partitioned cookies using Google Chrome:

  1. Open Google Chrome and navigate to the parent website embedding your partitioned service.
  2. Open Chrome DevTools by pressing Ctrl + Shift + I (or Option + Command + I on macOS).
  3. Switch to the Application tab and expand Cookies under the Storage tree.
  4. Select your embedded domain. Right-click the cookie table header and ensure Partition Key is enabled.
  5. Verify that your session cookie has a checkbox marked under the Partitioned column and displays the top-level site (e.g. https://site-a.com) under the Partition Key column.
  6. Inspect the Console tab to confirm no deprecation warnings are flagged for third-party cookie access.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.