{"record":{"id":"f1d0e8ad062b2b81","repo":"grafana/k6","slug":"browser-connect-w","errorCode":null,"errorMessage":"browser connect: %w","messagePattern":"browser connect: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser.go","lineNumber":166,"sourceCode":"\t// from doing unnecessary work.\n\t//\n\t// We need the connection to shutdown when browser.Close is called.\n\t// This is why we're using the internal context.\n\tvar err error\n\tb.conn, err = NewConnection(\n\t\tb.browserCtx,\n\t\tb.browserProc.WsURL(),\n\t\tb.logger,\n\t\tb.connectionOnAttachedToTarget,\n\t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"connecting to browser DevTools URL: %w\", err)\n\t}\n\n\t// We don't need to lock this because `connect()` is called only in NewBrowser\n\tb.defaultContext, err = NewBrowserContext(b.vuCtx, b, \"\", DefaultBrowserContextOptions(), b.logger)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"browser connect: %w\", err)\n\t}\n\tb.runOnClose = append(b.runOnClose, b.defaultContext.cleanup)\n\n\treturn b.initEvents()\n}\n\nfunc (b *Browser) disposeContext(id cdp.BrowserContextID) error {\n\tb.logger.Debugf(\"Browser:disposeContext\", \"bctxid:%v\", id)\n\n\taction := target.DisposeBrowserContext(id)\n\tif err := action.Do(cdp.WithExecutor(b.vuCtx, b.conn)); err != nil {\n\t\treturn fmt.Errorf(\"disposing browser context ID %s: %w\", id, err)\n\t}\n\tb.context = nil\n\n\treturn nil\n}\n","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser.go#L148-L184","documentation":"Returned by Browser.connect() when NewBrowserContext fails while creating the browser's internal default context (the implicit context every browser has before users call browser.newContext()). This happens immediately after the CDP connection is established, so it represents early per-context setup failing — option defaults being rejected or context creation CDP errors — rather than anything the script did with contexts.","triggerScenarios":"DefaultBrowserContextOptions() producing options the current Chrome rejects (version drift between k6's CDP layer and an unusual Chromium build); internal CDP errors while constructing the default context object on a flaky connection. Not directly triggerable by user API calls since the default context is created automatically.","commonSituations":"Exotic Chromium forks or very old/new Chrome versions whose context handling differs from what k6's bundled cdproto expects; connections that drop right after handshake; rarely seen on stock Chrome — treat as an environment/version mismatch signal.","solutions":["Use a mainstream Chrome/Chromium version compatible with your k6 release (check k6 browser docs for supported versions)","Retry once — transient connection drops during setup can surface here","Run with K6_BROWSER_DEBUG=true and capture the wrapped cause; report to k6 if it reproduces on stock Chrome","If on a custom Chromium fork, switch to standard Chrome to isolate the incompatibility"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const browser = chromium.launch();\n} catch (e) {\n  const m = String(e.message);\n  if (m.includes('browser connect')) {\n    // default-context creation failed during setup; usually version drift or a flaky connection\n    console.error('Default browser context failed to initialize; try a standard Chrome build and retry:', m);\n  }\n  throw e;\n}","preventionTips":["Use mainstream Chrome/Chromium versions matched to your k6 release","Retry once on setup failures caused by flaky connections","Capture K6_BROWSER_DEBUG=true output when reporting"],"tags":["cdp","browser-context","internal","version-compatibility"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}