Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/playwright-core/src/mcp/browser/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,11 @@ export function headerParser(arg: string | undefined, previous?: Record<string,
if (!arg)
return previous || {};
const result: Record<string, string> = previous || {};
const [name, value] = arg.split(':').map(v => v.trim());
const colonIndex = arg.indexOf(':');
if (colonIndex === -1)
return result;
const name = arg.substring(0, colonIndex).trim();
const value = arg.substring(colonIndex + 1).trim();
result[name] = value;
return result;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/mcp/cdp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,21 @@
});
expect(authHeader).toBe('Bearer 1234567890');
});

test('cdp server with headers containing colons', async ({ startClient, server }) => {
// Regression test for https://github.com/microsoft/playwright-mcp/issues/1417
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we usually use

test('cdp server with headers containing colons', {
  annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-mcp/issues/1417' },
},async ({ startClient, server }) => {

let customHeader = '';
server.setRoute('/json/version/', (req, res) => {
customHeader = req.headers['x-custom'];

Check failure on line 118 in tests/mcp/cdp.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Type 'string | string[]' is not assignable to type 'string'.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the lint error and we can merge this.

res.end();
});

const { client } = await startClient({ args: [`--cdp-endpoint=${server.PREFIX}`, '--cdp-header', 'X-Custom: http://example.com:8080/path'] });
expect(await client.callTool({
name: 'browser_navigate',
arguments: { url: server.HELLO_WORLD },
})).toHaveResponse({
isError: true,
});
expect(customHeader).toBe('http://example.com:8080/path');
});
Loading