Skip to content

[Bug]: [MCP] Normalize cookie domain handling and add domain filter for deletion #43274

Closed

Description

@alok-108

What's going on?

In Playwright MCP and CLI, when setting, listing, or deleting cookies:

  1. browser_cookie_set on about:blank without domain crashes with internal assertion error:
    When an agent or user invokes browser_cookie_set on a freshly opened browser session or blank tab (about:blank) without an explicit domain parameter:

    {
      "name": "browser_cookie_set",
      "arguments": { "name": "auth_token", "value": "xyz123" }
    }

    new URL(tab.page.url()) evaluates to hostname: "". Because params.domain || url.hostname results in an empty string (""), calling browserContext.addCookies([cookie]) throws:

    Error: browserBackend.callTool: Cookie should have a url or a domain/path pair
    

    Instead of failing with this internal Playwright assertion, it should report a clear, actionable error:

    Cannot infer cookie domain from current page URL "about:blank". Please specify "domain".
    
  2. browser_cookie_set unnecessarily attempts to parse tab.page.url() when domain is already provided:
    Even when an agent provides an explicit domain (e.g. domain: "example.com"), cookieSet unconditionally calls const url = new URL(tab.page.url()); before reading params.domain. If the tab URL is not a standard parseable URL, this throws unhandled TypeError: Invalid URL. When params.domain is specified, cookieSet should use it directly without requiring the page to be on an HTTP(S) URL.

  3. browser_cookie_list domain filtering is case-sensitive and fails on leading dots:
    In RFC 6265, cookie domains are case-insensitive and frequently include or omit leading dots (e.g. .example.com vs example.com).
    Currently:

    if (params.domain)
      cookies = cookies.filter(c => c.domain.includes(params.domain!));

    Calling browser_cookie_list with { domain: "EXAMPLE.COM" } or { domain: ".example.com" } returns "No cookies found" even when matching cookies exist, because includes performs a strict case-sensitive match.

  4. browser_cookie_delete lacks domain and path filtering:
    browser_cookie_delete only accepts name. If an agent has cookies with the same name across multiple domains or paths, it removes all of them. Adding optional domain and path to browser_cookie_delete aligns with Playwright's clearCookies API.

Version

Playwright main / 1.65.0-next

Activity

  1. pavelfeldman commented on Oct 12, 2026

    @pavelfeldman
    Member

    These would need to be broken apart into the individual cases - not all of them are reproducable.

  2. alok-108 commented on Oct 12, 2026

    @alok-108
    ContributorAuthor

    3. These would need to be broken apart into the individual cases - not all of them are reproducable.

    Thanks for the feedback, Pavel. I’ll split these cases and verify which ones are reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions