{"record":{"id":"8c65dc27cac20d89","repo":"karatelabs/karate","slug":"not-a-devtools-websocket-url-browserwebsocketurl","errorCode":null,"errorMessage":"not a devtools websocket url: {browserWebSocketUrl}","messagePattern":"not a devtools websocket url: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":584,"sourceCode":"                            .param(\"browserContextId\", contextId).send();\n                } catch (Exception ignored) {\n                    logger.debug(\"could not dispose orphan browser context: {}\", contextId);\n                }\n                throw e;\n            }\n        } finally {\n            browser.close();\n        }\n    }\n\n    /**\n     * Derive the page endpoint for a target from a browser endpoint on the same browser.\n     * ws://host:port/devtools/browser/&lt;id&gt; → ws://host:port/devtools/page/&lt;targetId&gt;\n     */\n    private static String pageWsUrlFrom(String browserWebSocketUrl, String targetId) {\n        int index = browserWebSocketUrl.indexOf(\"/devtools/\");\n        if (index == -1) {\n            throw new DriverException(\"not a devtools websocket url: \" + browserWebSocketUrl);\n        }\n        return browserWebSocketUrl.substring(0, index) + \"/devtools/page/\" + targetId;\n    }\n\n    /**\n     * Close all active drivers.\n     */\n    public static void closeAll() {\n        ACTIVE.forEach(CdpDriver::quit);\n    }\n\n    private void initialize() {\n        logger.debug(\"initializing CDP driver\");\n\n        // CRITICAL: Get main frame ID FIRST - needed by event handlers\n        // This works without Page.enable and ensures handlers can filter by frame\n        CdpResponse frameResponse = cdp.method(\"Page.getFrameTree\").send();\n        mainFrameId = frameResponse.getResult(\"frameTree.frame.id\");","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L566-L602","documentation":"pageWsUrlFrom derives a page WebSocket endpoint by rewriting the browser's /devtools/browser/<id> URL to /devtools/page/<targetId>. If the given URL does not contain '/devtools/', it is not a Chromium devtools browser endpoint and the rewrite is impossible, so this DriverException is thrown.","triggerScenarios":"Calling CdpDriver.connectNewContext (or anything that calls pageWsUrlFrom) with a browserWebSocketUrl lacking the '/devtools/' segment — e.g. ws://host:port alone, a raw socket path, or a vendor-specific endpoint format.","commonSituations":"Passing the raw debugging port URL (ws://localhost:9222) instead of the webSocketDebuggerUrl from /json/version; using a Playwright/Puppeteer-style browserWS endpoint whose path differs; typo in a configured driver URL.","solutions":["Use the exact webSocketDebuggerUrl reported by http://host:port/json/version (it always contains /devtools/browser/)","If behind a proxy that rewrites paths, ensure the /devtools/ prefix is preserved end-to-end","Validate the URL starts with ws(s)://host:port/devtools/browser/ before passing it to connectNewContext"],"exampleFix":"// before\nString url = \"ws://localhost:9222\";\nCdpDriver.connectNewContext(url, options);\n// after\nString url = \"ws://localhost:9222/devtools/browser/\" + browserId; // from /json/version\nCdpDriver.connectNewContext(url, options);","handlingStrategy":"validation","validationCode":"boolean ok = url.startsWith(\"ws://\") || url.startsWith(\"wss://\");\nok = ok && url.contains(\"/devtools/browser/\");\nif (!ok) throw new IllegalArgumentException(\"not a devtools browser websocket url: \" + url);","typeGuard":null,"tryCatchPattern":"try { return CdpDriver.connectNewContext(url, options); } catch (DriverException e) { if (e.getMessage().startsWith(\"not a devtools\")) { url = fetchDevtoolsUrl(host, port); return CdpDriver.connectNewContext(url, options); } throw e; }","preventionTips":["Always source the URL from /json/version webSocketDebuggerUrl","Never strip or rewrite the /devtools/ path segment when proxying","Validate URL shape in config loading before tests start"],"tags":["cdp","url-format","browser-automation"],"backgroundTag":"invalid-url-format","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}