{"record":{"id":"9262c4941155f878","repo":"puppeteer/puppeteer","slug":"could-not-find-devtoolsactiveport-for-options-ch","errorCode":null,"errorMessage":"Could not find DevToolsActivePort for ${options.channel} at ${portPath}","messagePattern":"Could not find DevToolsActivePort for (.+?) at (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/puppeteer-core/src/common/BrowserConnector.ts","lineNumber":181,"sourceCode":"        throw new Error(`Invalid DevToolsActivePort '${fileContent}' found`);\n      }\n      const port = parseInt(rawPort, 10);\n      if (isNaN(port) || port <= 0 || port > 65535) {\n        throw new Error(`Invalid port '${rawPort}' found`);\n      }\n      const browserWSEndpoint = `ws://localhost:${port}${rawPath}`;\n      const WebSocketClass = await getWebSocketTransportClass();\n      const connectionTransport = await WebSocketClass.create(\n        browserWSEndpoint,\n        headers,\n        options.logger,\n      );\n      return {\n        connectionTransport: connectionTransport,\n        endpointUrl: browserWSEndpoint,\n      };\n    } catch (error) {\n      throw new Error(\n        `Could not find DevToolsActivePort for ${options.channel} at ${portPath}`,\n        {\n          cause: error,\n        },\n      );\n    }\n  }\n  throw new Error('Invalid connection options');\n}\n\nasync function getWSEndpoint(\n  browserURL: string,\n  headers?: Record<string, string>,\n): Promise<string> {\n  const endpointURL = new URL('/json/version', browserURL);\n\n  try {\n    const result = await globalThis.fetch(endpointURL.toString(), {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/puppeteer/puppeteer/blob/d484e21c17f6023826fefdcdeeb553e04a7aaed8/packages/puppeteer-core/src/common/BrowserConnector.ts#L163-L199","documentation":"Umbrella error thrown by the channel-based connect branch when ANY error occurs while reading or parsing DevToolsActivePort or opening the resulting WebSocket. The original error is attached as `cause`. The message reports the channel and the path that failed.","triggerScenarios":"Any failure inside the try-block: file not found, permission denied, invalid content (211/212), or the WebSocket transport failing to connect to ws://localhost:<port><path>. The catch wraps it with channel + path context.","commonSituations":"Connecting via channel while Chrome is not running (ENOENT); Chrome running but DevTools not enabled; port already released because Chrome shut down between detection and connect; firewall blocking localhost WS.","solutions":["Inspect error.cause to find the real failure (ENOENT, EACCES, Invalid port, WS reject).","Ensure Chrome for Testing / the chosen channel is actually running with --remote-debugging-port.","Use puppeteer.launch() to have puppeteer start Chrome itself, avoiding stale-port issues.","Prefer browserWSEndpoint when you know the endpoint directly."],"exampleFix":"// before\ntry { await puppeteer.connect({ channel: 'chrome' }); }\ncatch (e) { /* opaque error */ }\n\n// after\ntry { await puppeteer.connect({ channel: 'chrome' }); }\ncatch (e) { console.error(e.message, e.cause); }\n// or: launch Chrome yourself\nconst browser = await puppeteer.launch({ channel: 'chrome' });","handlingStrategy":"try-catch","validationCode":"// Pre-flight: confirm Chrome is running and DevTools port file exists.\nimport fs from 'node:fs';\nif (!fs.existsSync(portPath)) {\n  throw new Error('Chrome not running or DevTools not enabled');\n}\nawait puppeteer.connect({ channel: 'chrome' });","typeGuard":"// No type-level guard; this is a runtime/IO failure. Inspect error.cause instead.","tryCatchPattern":"try { await puppeteer.connect({ channel: 'chrome' }); }\ncatch (e) {\n  console.error(e.message, e.cause);\n  if (e.cause?.code === 'ENOENT') { /* Chrome not running */ }\n  else if (e.cause?.code === 'EACCES') { /* permission denied */ }\n  else throw e;\n}","preventionTips":["Always inspect error.cause — the umbrella message hides the root reason.","Confirm Chrome is running with --remote-debugging-port before channel connect.","Prefer puppeteer.launch() when you do not need to attach to an existing instance.","Use browserWSEndpoint when you already know the WS URL."],"tags":["connect","channel","devtools","diagnostics"],"backgroundTag":null,"analyzedSha":"d484e21c17f6023826fefdcdeeb553e04a7aaed8","analyzedAt":"2026-08-12T06:33:19.665Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}