curl -sS "https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
// Step 1: fetch the discovery document
const discovery = await fetch(
"https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
).then((response) => response.json());
// Step 2: open a WebSocket using the pre-built URL
const socket = new WebSocket(discovery.webSocketDebuggerUrl);
socket.addEventListener("open", () => {
console.log("CDP WebSocket connected");
});
{
"Browser": "Chrome/136.0.0.0",
"Protocol-Version": "1.3",
"User-Agent": "Mozilla/5.0 ...",
"V8-Version": "13.6.233.8",
"WebKit-Version": "537.36 (@revision)",
"webSocketDebuggerUrl": "wss://api.adscrawl.net/cdp/sessions/SESSION_ID/devtools/browser/BROWSER_ID?token=<data-token>"
}
远程 CDP
发现 CDP 端点
获取会话的 Chrome DevTools Protocol 发现 JSON,包括已预重写的 WebSocket 调试器 URL。
GET
/
cdp
/
sessions
/
{sessionId}
/
json
/
version
curl -sS "https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
// Step 1: fetch the discovery document
const discovery = await fetch(
"https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
).then((response) => response.json());
// Step 2: open a WebSocket using the pre-built URL
const socket = new WebSocket(discovery.webSocketDebuggerUrl);
socket.addEventListener("open", () => {
console.log("CDP WebSocket connected");
});
{
"Browser": "Chrome/136.0.0.0",
"Protocol-Version": "1.3",
"User-Agent": "Mozilla/5.0 ...",
"V8-Version": "13.6.233.8",
"WebKit-Version": "537.36 (@revision)",
"webSocketDebuggerUrl": "wss://api.adscrawl.net/cdp/sessions/SESSION_ID/devtools/browser/BROWSER_ID?token=<data-token>"
}
检索会话的 Chrome DevTools Protocol 发现 JSON。响应包含一个
webSocketDebuggerUrl,已预重写为公共的、会话范围的 CDP WebSocket 路径。直接使用它,无需手动构造 URL。
响应
| Status | 含义 |
|---|---|
200 | Chrome 发现 JSON,包含已重写的 webSocketDebuggerUrl。 |
401 | 数据令牌缺失或无效。 |
404 / 409 / 410 | 会话缺失、正在停止或已过期。 |
502 | 无法从云端后端获取上游 CDP 发现。 |
503 | 会话后端不可用。 |
通过 WebSocket 连接
升级到浏览器 CDP 端点的 WebSocket 连接。CDP 消息在你的客户端和云端运行的 Chromium 实例之间双向代理。直接使用发现端点返回的webSocketDebuggerUrl,而非手动构造此 URL。
| Status | 含义 |
|---|---|
101 | WebSocket 升级成功;CDP 消息现在双向代理。 |
401 | 数据令牌缺失或无效。 |
404 / 409 / 410 | 会话缺失、正在停止或已过期。 |
502 | 云端后端 CDP 连接在 101 升级前失败。 |
503 | 会话后端不可用。 |
curl -sS "https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
// Step 1: fetch the discovery document
const discovery = await fetch(
"https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
).then((response) => response.json());
// Step 2: open a WebSocket using the pre-built URL
const socket = new WebSocket(discovery.webSocketDebuggerUrl);
socket.addEventListener("open", () => {
console.log("CDP WebSocket connected");
});
{
"Browser": "Chrome/136.0.0.0",
"Protocol-Version": "1.3",
"User-Agent": "Mozilla/5.0 ...",
"V8-Version": "13.6.233.8",
"WebKit-Version": "537.36 (@revision)",
"webSocketDebuggerUrl": "wss://api.adscrawl.net/cdp/sessions/SESSION_ID/devtools/browser/BROWSER_ID?token=<data-token>"
}