Skip to content

[MCP]: browser_cookie_set fails with internal assertion error when domain is omitted on blank page #43309

Closed

Description

@alok-108

What's going on?

Following up on closed issue #43274 to isolate individual reproducible cases. This report covers the error handling when invoking browser_cookie_set on a blank tab (about:blank) without an explicit domain.

When an agent or user invokes browser_cookie_set immediately after opening a browser or on an unnavigated tab (about:blank):

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

In packages/playwright-core/src/tools/backend/cookies.ts (lines 103–109):

const url = new URL(tab.page.url());
const cookie: any = {
  name: params.name,
  value: params.value,
  domain: params.domain || url.hostname,
  path: params.path || '/',
};

On about:blank, new URL('about:blank').hostname is "". When params.domain is omitted, cookie.domain becomes "".
When passed to browserContext.addCookies([cookie]), Playwright's internal validation in packages/playwright-core/src/server/network.ts line 165 checks:

assert(c.url || (c.domain && c.path), 'Cookie should have a url or a domain/path pair');

Because c.domain === "", (c.domain && c.path) evaluates to "" (falsy), and Playwright throws an internal assertion failure:

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

Reproduction

MCP Cookie Set about:blank Repro

test('browser_cookie_set on about:blank without domain', async ({ startClient }) => {
  const { client } = await startClient({ config: { capabilities: ['storage'] } });

  const response = await client.callTool({
    name: 'browser_cookie_set',
    arguments: { name: 'session_id', value: 'xyz123' },
  });

  // Fails with: Error: browserBackend.callTool: Cookie should have a url or a domain/path pair
});

Expected Behavior

Rather than crashing with an internal core assertion error (Cookie should have a url or a domain/path pair), browser_cookie_set should validate that the domain can be determined and report an actionable error to the client/LLM:

Cannot infer cookie domain from current page URL "about:blank". Please specify "domain".

Version

Playwright main / 1.65.0-next

Activity

  1. alok-108 commented on Oct 12, 2026

    @alok-108
    ContributorAuthor

    I have tested and verified this case independently in isolation on blank sessions. I will be opening a PR shortly to handle this with a clear validation error.

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