{"record":{"id":"d75eacbcba52042b","repo":"microsoft/playwright","slug":"could-not-connect-to-channel-n-remotedebuggin","errorCode":null,"errorMessage":"Could not connect to ${channel}.\\n${remoteDebuggingHint(channel)}","messagePattern":"Could not connect to (.+?)\\.\\\\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/chromium/chromium.ts","lineNumber":111,"sourceCode":"      headersMap = headersArrayToObject(options.headers, false);\n\n    if (!headersMap)\n      headersMap = { 'User-Agent': getUserAgent() };\n    else if (headersMap && !Object.keys(headersMap).some(key => key.toLowerCase() === 'user-agent'))\n      headersMap['User-Agent'] = getUserAgent();\n\n    const channel = isChromiumChannelName(endpointURL) ? endpointURL : undefined;\n    if (channel)\n      endpointURL = await resolveChannelEndpoint(progress, endpointURL);\n\n    let wsEndpoint: string;\n    let chromeTransport: WebSocketTransport;\n    try {\n      wsEndpoint = await urlToWSEndpoint(progress, endpointURL, headersMap);\n      chromeTransport = await WebSocketTransport.connect(progress, wsEndpoint, { headers: headersMap, followRedirects: true, debugLogHeader: 'x-playwright-debug-log' });\n    } catch (e) {\n      if (channel)\n        throw new Error(`Could not connect to ${channel}.\\n${remoteDebuggingHint(channel)}`);\n      throw e;\n    }\n    const closeAndWait = async () => await chromeTransport.closeAndWait();\n    return this._connectOverCDPImpl(progress, chromeTransport, closeAndWait, options, onClose);\n  }\n\n  private async _connectOverCDPImpl(progress: Progress, transport: ConnectionTransport, closeAndWait: () => Promise<void>, options: types.LaunchOptions & { isLocal?: boolean, noDefaults?: boolean, artifactsDir?: string }, onClose?: () => Promise<void>) {\n    let artifactsDir: string;\n    const tempDirectories: string[] = [];\n    if (options.artifactsDir) {\n      artifactsDir = options.artifactsDir;\n    } else {\n      artifactsDir = await progress.race(fs.promises.mkdtemp(ARTIFACTS_FOLDER));\n      tempDirectories.push(artifactsDir);\n    }\n    const doCleanup = async () => {\n      await removeFolders(tempDirectories);\n      const cb = onClose;","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/chromium/chromium.ts#L93-L129","documentation":"Thrown in Chromium.connectOverCDP when the WS-endpoint resolution + WebSocket connect fails AND the endpointURL was recognized as a Chromium channel name (e.g. 'chrome'). It surfaces a remote-debugging hint because connecting by channel name requires that browser already be running with remote debugging enabled.","triggerScenarios":"await chromium.connectOverCDP('chrome') (or 'msedge') when that browser is not running with --remote-debugging-port=0 / remote debugging enabled, or the DevToolsActivePort file is missing.","commonSituations":"Trying to attach to a user's already-running Chrome that was started normally (no debugging flag). Wrong/old user-data-dir. Browser launched by a desktop session that did not enable remote debugging.","solutions":["Launch Chrome with remote debugging yourself: 'chrome --remote-debugging-port=9222' and connect to 'http://localhost:9222'.","In Chrome, enable chrome://inspect 'Allow remote debugging for this browser instance' as the embedded hint suggests.","Connect by explicit wsEndpoint URL (ws://host:port/devtools/browser/...) instead of by channel name."],"exampleFix":"// before\nconst b = await chromium.connectOverCDP('chrome');\n// after\n// shell: google-chrome --remote-debugging-port=9222\nconst b = await chromium.connectOverCDP('http://localhost:9222');","handlingStrategy":"validation","validationCode":"async function probeCDP(httpURL: string): Promise<boolean> {\n  try {\n    const r = await fetch(httpURL + '/json/version');\n    return r.ok && !!(await r.json()).webSocketDebuggerUrl;\n  } catch { return false; }\n}","typeGuard":"function isChannelName(url: string): boolean {\n  return /^(chrome|msedge|chromium)/i.test(url) && !/^https?:\\/\\//.test(url);\n}","tryCatchPattern":"try {\n  browser = await chromium.connectOverCDP('chrome');\n} catch (e) {\n  if (/Could not connect to/.test(String(e.message))) {\n    throw new Error('Start Chrome with --remote-debugging-port=9222, then connect by http URL');\n  }\n  throw e;\n}","preventionTips":["Prefer connecting by explicit http/ws URL rather than channel name in production scripts.","Launch Chrome yourself with --remote-debugging-port so the endpoint is deterministic."],"tags":["cdp","connect","chromium","remote-debugging"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}