Skip to content

Commit 370678f

Browse files
committed
feat: add precheck for CDP and Bridge mode availability
- CDP: curl WebSocket handshake on port 9222 - Bridge: curl Socket.IO on port 3766 - Route to Puppeteer if both unavailable - Add implicit login state as CDP trigger
1 parent dc34d57 commit 370678f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

skills/browser/SKILL.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,29 @@ This skill has three modes. Choose based on the user's intent:
4646
| Mode | When to use | How it works |
4747
|------|------------|-------------|
4848
| **Puppeteer (default)** | User wants to browse a URL, scrape data, test UI — no need for their own browser | Launches a new headless Chrome, isolated from user's browser |
49-
| **CDP mode** | User says "connect to my Chrome", "control my browser", "CDP", "remote debugging", or wants to operate their existing browser | Connects to user's Chrome via DevTools Protocol. Requires remote debugging enabled (`chrome://inspect` > "Allow remote debugging"). No extension needed |
49+
| **CDP mode** | User says "connect to my Chrome", "control my browser", "CDP", "remote debugging", or wants to operate their existing browser. Also use when the task **implicitly requires login state** (e.g., "check my orders", "open my dashboard", "look at my account") | Connects to user's Chrome via DevTools Protocol. Requires remote debugging enabled (`chrome://inspect` > "Allow remote debugging"). No extension needed |
5050
| **Bridge mode** | User explicitly mentions "bridge", "extension", or has Midscene Chrome Extension installed and prefers to use it | Connects to user's Chrome via the Midscene Chrome Extension |
5151

5252
**CDP vs Bridge**: Both control the user's real Chrome with login sessions preserved. CDP only needs a Chrome setting toggle; Bridge needs a Chrome Extension installed. If the user doesn't specify, prefer **CDP mode** as it has fewer prerequisites.
5353

54+
### Precheck: detect available connection modes
55+
56+
Before using CDP or Bridge mode, run a quick precheck to verify the target is reachable. This avoids long timeouts when the user hasn't enabled remote debugging or installed the extension.
57+
58+
```bash
59+
# CDP precheck (port 9222, 2s timeout) — returns "101" if available
60+
curl -s --max-time 2 -o /dev/null -w "%{http_code}" -H "Upgrade: websocket" -H "Connection: Upgrade" -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" http://127.0.0.1:9222/devtools/browser
61+
62+
# Bridge precheck (port 3766, 2s timeout) — returns "200" or "400" if extension is listening
63+
curl -s --max-time 2 -o /dev/null -w "%{http_code}" http://127.0.0.1:3766/socket.io/?EIO=4&transport=polling
64+
```
65+
66+
**How to use precheck results:**
67+
- CDP returns `101` → CDP mode is available, use `--cdp`
68+
- Bridge returns `200` or `400` → Bridge extension is listening, use `--bridge`
69+
- Both fail → fall back to Puppeteer mode, or ask the user to enable remote debugging
70+
- Both available and user didn't specify → prefer CDP
71+
5472
## Prerequisites
5573

5674
Midscene requires models with strong visual grounding capabilities. The following environment variables must be configured — either as system environment variables or in a `.env` file in the current working directory (Midscene loads `.env` automatically):

0 commit comments

Comments
 (0)