You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add WebSocket endpoint and custom headers support (#404)
## Summary
Add support for connecting to Chrome via WebSocket endpoint with custom
headers, enabling authenticated remote debugging scenarios and providing
an alternative to the HTTP-based connection method.
## What's New
This PR introduces two new CLI arguments:
- **`--wsEndpoint` / `-w`**: Connect directly to Chrome using a
WebSocket URL
- Example: `ws://127.0.0.1:9222/devtools/browser/<id>`
- Alternative to `--browserUrl` (mutually exclusive)
- **`--wsHeaders`**: Pass custom headers for WebSocket connections (JSON
format)
- Example: `'{"Authorization":"Bearer token"}'`
- Only works with `--wsEndpoint`
## Use Cases
- **Authenticated remote debugging**: Use API keys, tokens, or custom
auth headers
- **Secured instances**: Connect to browser instances requiring
authentication
Copy file name to clipboardExpand all lines: README.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -284,6 +284,14 @@ The Chrome DevTools MCP server supports the following configuration option:
284
284
Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.
285
285
-**Type:** string
286
286
287
+
-**`--wsEndpoint`, `-w`**
288
+
WebSocket endpoint to connect to a running Chrome instance (e.g., ws://127.0.0.1:9222/devtools/browser/<id>). Alternative to --browserUrl.
289
+
-**Type:** string
290
+
291
+
-**`--wsHeaders`**
292
+
Custom headers for WebSocket connection in JSON format (e.g., '{"Authorization":"Bearer token"}'). Only works with --wsEndpoint.
293
+
-**Type:** string
294
+
287
295
-**`--headless`**
288
296
Whether to run in headless (no UI) mode.
289
297
-**Type:** boolean
@@ -343,6 +351,27 @@ Pass them via the `args` property in the JSON configuration. For example:
343
351
}
344
352
```
345
353
354
+
### Connecting via WebSocket with custom headers
355
+
356
+
You can connect directly to a Chrome WebSocket endpoint and include custom headers (e.g., for authentication):
To get the WebSocket endpoint from a running Chrome instance, visit `http://127.0.0.1:9222/json/version` and look for the `webSocketDebuggerUrl` field.
374
+
346
375
You can also run `npx chrome-devtools-mcp@latest --help` to see all available configuration options.
Copy file name to clipboardExpand all lines: src/cli.ts
+66-4Lines changed: 66 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ export const cliOptions = {
14
14
description:
15
15
'Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.',
16
16
alias: 'u',
17
+
conflicts: 'wsEndpoint',
17
18
coerce: (url: string|undefined)=>{
18
19
if(!url){
19
20
return;
@@ -26,6 +27,54 @@ export const cliOptions = {
26
27
returnurl;
27
28
},
28
29
},
30
+
wsEndpoint: {
31
+
type: 'string',
32
+
description:
33
+
'WebSocket endpoint to connect to a running Chrome instance (e.g., ws://127.0.0.1:9222/devtools/browser/<id>). Alternative to --browserUrl.',
0 commit comments