{"record":{"id":"bc8f7c0a774c2bc5","repo":"grafana/k6","slug":"internal-error-while-getting-browser-target-info","errorCode":null,"errorMessage":"internal error while getting browser target info: %w","messagePattern":"internal error while getting browser target info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/js/modules/k6/browser/common/browser.go","lineNumber":260,"sourceCode":"\t\t\t\t} else if event.typ == EventConnectionClose {\n\t\t\t\t\tb.logger.Debugf(\"Browser:initEvents:EventConnectionClose\", \"\")\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}()\n\n\taction := target.SetAutoAttach(true, true).WithFlatten(true)\n\tif err := action.Do(cdp.WithExecutor(b.vuCtx, b.conn)); err != nil {\n\t\treturn fmt.Errorf(\"internal error while auto-attaching to browser pages: %w\", err)\n\t}\n\n\t// Target.setAutoAttach has a bug where it does not wait for new Targets being attached.\n\t// However making a dummy call afterwards fixes this.\n\t// This can be removed after https://chromium-review.googlesource.com/c/chromium/src/+/2885888 lands in stable.\n\taction2 := target.GetTargetInfo()\n\tif _, err := action2.Do(cdp.WithExecutor(b.vuCtx, b.conn)); err != nil {\n\t\treturn fmt.Errorf(\"internal error while getting browser target info: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// connectionOnAttachedToTarget is called when Connection receives an attachedToTarget\n// event. Returning false makes the connection release the target instead of\n// adopting it. Targets from the connection's own browser context and from\n// the default browser context are accepted.\nfunc (b *Browser) connectionOnAttachedToTarget(eva *target.EventAttachedToTarget) bool {\n\tb.contextMu.RLock()\n\tdefer b.contextMu.RUnlock()\n\tif b.context != nil && b.context.id == eva.TargetInfo.BrowserContextID {\n\t\treturn true\n\t}\n\treturn b.defaultContext.id == eva.TargetInfo.BrowserContextID\n}\n","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/browser.go#L242-L278","documentation":"Right after setAutoAttach, connect() issues a dummy Target.getTargetInfo call to work around a Chromium bug where setAutoAttach does not wait for pending target attachments (see the chromium-review link in the source). This error wraps that follow-up CDP call failing, i.e. the connection or browser died within milliseconds of the previous command, or the endpoint partially implements CDP.","triggerScenarios":"Connection loss between setAutoAttach and GetTargetInfo; browser process killed (OOM, SIGKILL from CI timeouts) moments after startup; a CDP proxy dropping frames; protocol-level mismatch with an unsupported browser build.","commonSituations":"CI jobs killing the browser with strict timeouts; memory-constrained runners; flaky WS proxies in remote-browser setups.","solutions":["Check whether the browser process was killed (dmesg OOM lines, container exit code 137) and raise memory limits","Stabilize the remote endpoint / proxy between k6 and the browser","Match Chromium or headless-shell version to the k6 release notes","Capture K6_BROWSER_LOG=debug output and report if it persists on stock versions"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const browser = chromium.launch();\n} catch (e) {\n  if (String(e).includes('getting browser target info')) {\n    // connection dropped right after connect; check for OOM-killed browser\n    // (exit 137, dmesg), stabilize environment, retry once\n  }\n}","preventionTips":["Watch for OOM kills on browser containers during startup","Give the browser a few seconds of warm-up before heavy load","Use stable network paths to remote browsers"],"tags":["cdp","browser","gettargetinfo","connection","startup"],"backgroundTag":"cdp-protocol-error","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}