Fix CDP connection failure on IPv6-first systems (#717)

Use 127.0.0.1 instead of localhost when constructing CDP URL from port
number, since Chrome only binds to IPv4. This prevents connection
failures on systems like Ubuntu 24.04 where localhost resolves to ::1.

Co-authored-by: hyunjinee <leehj0110@kakao.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jin.2
2026-03-11 04:15:21 -05:00
committed by GitHub
co-authored by hyunjinee Claude Opus 4.6
parent def2fd90fa
commit 417428463b
+3 -3
View File
@@ -1523,10 +1523,10 @@ export class BrowserManager {
cdpUrl = cdpEndpoint;
} else if (/^\d+$/.test(cdpEndpoint)) {
// Numeric string - treat as port number (handles JSON serialization quirks)
cdpUrl = `http://localhost:${cdpEndpoint}`;
cdpUrl = `http://127.0.0.1:${cdpEndpoint}`;
} else {
// Unknown format - still try as port for backward compatibility
cdpUrl = `http://localhost:${cdpEndpoint}`;
cdpUrl = `http://127.0.0.1:${cdpEndpoint}`;
}
const browser = await chromium
@@ -1534,7 +1534,7 @@ export class BrowserManager {
.catch(() => {
throw new Error(
`Failed to connect via CDP to ${cdpUrl}. ` +
(cdpUrl.includes('localhost')
(cdpUrl.includes('127.0.0.1')
? `Make sure the app is running with --remote-debugging-port=${cdpEndpoint}`
: 'Make sure the remote browser is accessible and the URL is correct.')
);