-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Add CDP headers support for authenticated connections #858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
README.md
Outdated
@@ -231,6 +233,20 @@ state [here](https://playwright.dev/docs/auth). | |||
} | |||
``` | |||
|
|||
#### CDP Headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this from the readme, it is very niche and is already mentioned above.
src/program.ts
Outdated
@@ -67,6 +68,18 @@ program | |||
console.error('The --vision option is deprecated, use --caps=vision instead'); | |||
options.caps = 'vision'; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have two different parse methods, do it like commaSeparatedList instead.
@pavelfeldman
|
Sorry it seems like this requires a rebase now. |
- Add cdpHeaders option to browser configuration - Support --cdp-headers CLI option for JSON header specification - Add PLAYWRIGHT_MCP_CDP_HEADERS environment variable support - Update CdpContextFactory to pass headers to connectOverCDP - Add JSON parsing with error handling for CLI headers - Add tests for headers functionality and invalid JSON handling - Update documentation with usage examples This enables connecting to CDP endpoints that require authentication, such as AWS Bedrock AgentCore Browser instances. Unify CDP headers parsing and improve error messages - Remove duplicate CDP headers documentation from README - Replace manual JSON parsing with parseJsonObject function - Use InvalidArgumentError for user-friendly error messages - Maintain consistency with other option parsers like commaSeparatedList Addresses review feedback on standardizing parse methods. fix: resolve ESLint violations
e88876a
to
ea8b6da
Compare
@pavelfeldman |
src/browserContextFactory.ts
Outdated
@@ -128,7 +128,11 @@ class CdpContextFactory extends BaseContextFactory { | |||
} | |||
|
|||
protected override async _doObtainBrowser(): Promise<playwright.Browser> { | |||
return playwright.chromium.connectOverCDP(this.config.browser.cdpEndpoint!); | |||
const options: any = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure types are in order here.
src/config.ts
Outdated
export function parseJsonObject(value: string | undefined): Record<string, string> | undefined { | ||
if (!value) | ||
return undefined; | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code could be simplified a lot, did you mean to parse JSON first and then assert the type of the parsed value?
@pavelfeldman |
Summary
Adds support for passing authentication headers when connecting to CDP endpoints, enabling connections to authenticated browser instances like AWS Bedrock AgentCore Browser.
Background
Modern AI agent platforms like AWS Bedrock AgentCore provide managed browser instances that require authenticated CDP connections. Currently, playwright-mcp cannot pass authentication headers when connecting to CDP endpoints, preventing integration with these enterprise-grade services.
Amazon Bedrock AgentCore Browser service provides managed, secure, cloud-based browser instances that enable AI agents to interact with websites at scale for tasks like form completion and web navigation. These browser instances require authenticated CDP connections with proper headers for security and access control.
Changes
cdpHeaders
option to browser configuration type definitions--cdp-headers
option with JSON parsing and validationPLAYWRIGHT_MCP_CDP_HEADERS
for configurationCdpContextFactory
to pass headers to Playwright'sconnectOverCDP
Usage Examples
CLI Usage
bash
Environment Variable
bash
Configuration File
json
Compatibility
Use Cases
This feature enables integration with:
References