Skip to content
Open
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
13 changes: 12 additions & 1 deletion scripts/browser-discovery.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,20 @@ export async function selectBrowser(override = null) {
// 兜底:扫描常用固定端口
// 适用场景:用户手动 --remote-debugging-port=9222 启动浏览器,
// 此时 DevToolsActivePort 可能不在默认 user-data-dir。
// 返回 { port, wsPath } 或 null(需 fetch wsPath 因为 Chrome 要求完整 UUID 路径)
export async function findFallbackPort() {
for (const port of [9222, 9229, 9333]) {
if (await checkPort(port)) return port;
if (!(await checkPort(port))) continue;
try {
const resp = await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(3000) });
const data = await resp.json();
const wsUrl = data.webSocketDebuggerUrl;
if (wsUrl) {
const u = new URL(wsUrl);
return { port, wsPath: u.pathname };
}
} catch {}
return { port, wsPath: null };
}
return null;
}
8 changes: 4 additions & 4 deletions scripts/cdp-proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ async function discoverChromePort() {
);
}
// 仅在「从未成功连接 + 无偏好/override」时允许固定端口兜底(手动 --remote-debugging-port 启动场景)
const fallbackPort = await findFallbackPort();
if (fallbackPort !== null) {
const fallback = await findFallbackPort();
if (fallback !== null) {
connectedBrowser = { id: 'unknown', label: '未知(通过手动调试端口连接)', source: 'fallback' };
console.log(`[CDP Proxy] 通过手动调试端口连接: ${fallbackPort}`);
return { port: fallbackPort, wsPath: null };
console.log(`[CDP Proxy] 通过手动调试端口连接: ${fallback.port}${fallback.wsPath ? ',带 wsPath' : ''}`);
return { port: fallback.port, wsPath: fallback.wsPath };
}
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/check-deps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ async function resolveAndReport(override) {

case 'empty': {
// 末路兜底:尝试常见固定端口(用户手动 --remote-debugging-port=9222 启动的场景)
const fallbackPort = await findFallbackPort();
if (fallbackPort) {
console.log(`browser: ok (port ${fallbackPort}) [通过手动调试端口连接]`);
const fallback = await findFallbackPort();
if (fallback) {
console.log(`browser: ok (port ${fallback.port}) [通过手动调试端口连接]`);
return { proceed: true };
}
console.log('browser: 未连接 — 没有任何浏览器打开远程调试开关');
Expand Down