playwright: [Bug]: WebKit 18.4: `document.cookie` returns empty string in iframe despite cookie being present in HTTP requests

Version

1.51.1

Steps to reproduce

  1. Clone the repository at https://github.com/jhogervorst/playwright-webkit-iframe-cookie-issue
  2. Run npm install
  3. Start the server: npm run server
  4. Run the tests: npm test
  5. The test will fail specifically for WebKit 18.4 on Linux, while passing for all other browsers and platforms

Expected behavior

When a cookie is set on the parent domain with SameSite=Lax and proper domain scoping, it should be accessible via document.cookie within an iframe on a subdomain. This is the behavior observed in Chromium and Firefox, as well as all browsers on macOS.

Actual behavior

In WebKit 18.4 on Linux:

  1. The cookie is successfully set on the parent domain (verified via document.cookie on parent page)
  2. The cookie is present in HTTP requests from the iframe (verified via API call)
  3. However, document.cookie returns an empty string within the iframe
  4. This behavior is specific to WebKit 18.4 on Linux - all other browsers and platforms work as expected

The test results can be viewed in the GitHub Actions workflow run at: https://github.com/jhogervorst/playwright-webkit-iframe-cookie-issue/actions/runs/14195304583

Additional context

This issue appears to be related to WebKit 18.4’s handling of cookie access in iframes. The test demonstrates that while the cookie is properly sent in HTTP requests (indicating it’s present in the browser’s cookie store), it’s not accessible via JavaScript in the iframe context. This could be a regression in WebKit’s cookie handling or a change in security policies.

The issue was not present in WebKit 18.2 and its corresponding Playwright version, suggesting this is a regression introduced in WebKit 18.4.

Environment

  System:
    OS: Linux 6.8 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (4) x64 AMD EPYC 7763 64-Core Processor
    Memory: 14.55 GB / 15.62 GB
    Container: Yes
  Binaries:
    Node: 20.19.0 - /opt/hostedtoolcache/node/20.19.0/x64/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.8.2 - /opt/hostedtoolcache/node/20.19.0/x64/bin/npm
  Languages:
    Bash: 5.2.21 - /usr/bin/bash
  npmPackages:
    @playwright/test: ^1.51.1 => 1.51.1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (12 by maintainers)

Most upvoted comments

This got fixed upstream in https://github.com/WebKit/WebKit/pull/43899, so this will be fixed once Playwright rolls there (couple weeks).

Should be fixed and available in Canary in 12-24h.

just to confirm that this also fixed the other issue I reported in https://github.com/microsoft/playwright/issues/35269 so it was actually the same cause in the end

Thanks everyone! We just confirmed (using version 1.53.0-alpha-2025-04-16) that the fix resolves the issue for us.

Oh we have news! We can repro locally with /etc/hosts when we use example.test as the domain, but it works fine for example.com. Weird.

Here’s what it looks like in Epiphany Canary:

Image

That’s yet another behaviour, where there’s no cookie in the iframe, but API requests from the iframe also don’t have that cookie. The behaviour is the same in Epiphany stable.

I can reproduce your findings @jhogervorst. Looks like this is issue is distinct from https://github.com/microsoft/playwright/issues/35269.

This means it’s most likely a regression in WebKit for Linux. Before we file a bug report with WebKit, i’ll check if I can repro this in Epiphany.