Skip to content
Merged
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
5 changes: 4 additions & 1 deletion packages/playwright-core/src/mcp/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ 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(':');

const name = colonIndex === -1 ? arg.trim() : arg.substring(0, colonIndex).trim();
const value = colonIndex === -1 ? '' : arg.substring(colonIndex + 1).trim();
result[name] = value;
return result;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/mcp/cdp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,29 @@ test('cdp server with headers', async ({ startClient, server }) => {
});
expect(authHeader).toBe('Bearer 1234567890');
});

test('cdp server with empty and complex headers', async ({ startClient, server }) => {
let customHeader = '';
let emptyHeader = '';
server.setRoute('/json/version/', (req, res) => {
customHeader = req.headers['x-forwarded-proto'] as string;
emptyHeader = req.headers['x-empty'] as string;
res.end();
});

const { client } = await startClient({
args: [
`--cdp-endpoint=${server.PREFIX}`,
'--cdp-header', 'X-Forwarded-Proto: value:with:colons',
'--cdp-header', 'X-Empty'
]
});
expect(await client.callTool({
name: 'browser_navigate',
arguments: { url: server.HELLO_WORLD },
})).toHaveResponse({
isError: true,
});
expect(customHeader).toBe('value:with:colons');
expect(emptyHeader).toBe('');
});
Loading