{"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":"error","filePath":"internal/js/modules/k6/browser/common/browser.go","lineNumber":262,"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 will stop the event from being processed by the connection.\nfunc (b *Browser) connectionOnAttachedToTarget(eva *target.EventAttachedToTarget) bool {\n\t// This allows to attach targets to the same browser context as the current\n\t// one, and to the default browser context.\n\t//\n\t// We don't want to hold the lock for the entire function\n\t// (connectionOnAttachedToTarget) run duration, because we want to avoid\n\t// possible lock contention issues with the browser context being closed while\n\t// we're waiting for it. So, we do the lock management in a function with its\n\t// own defer.\n\tisAllowedBrowserContext := func() bool {\n\t\tb.contextMu.RLock()","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser.go#L244-L280","documentation":"Returned by Browser.initEvents when target.GetTargetInfo() fails. k6 deliberately makes this dummy call right after SetAutoAttach to work around a Chromium bug where setAutoAttach does not wait for new targets (see the linked Chromium review in the source). Its failure indicates the CDP session is broken at a point where even a trivial read-only call fails, so browser creation aborts with this 'internal error' message.","triggerScenarios":"Same family as the auto-attach failure: connection closed/dropped during setup; remote Chrome process exiting mid-handshake; timeout cutting the round-trip; Chrome that became unresponsive (hung renderer/browser process).","commonSituations":"Chrome hanging under memory pressure right after start; container OOM killing the browser between the two CDP calls; flaky networking to remote browsers; extremely rare with healthy local Chrome.","solutions":["Check Chrome/browser container memory limits and logs for OOM or hangs","Increase K6_BROWSER_TIMEOUT for slow or loaded machines","Confirm remote Chrome is not being restarted concurrently (orchestrator, browserless pool recycling)","Retry launch once; if it consistently fails, capture K6_BROWSER_DEBUG=true output and report to k6"],"exampleFix":"# before\nk6 run test.js  # browser hangs during setup, call times out\n\n# after\nK6_BROWSER_DEBUG=true K6_BROWSER_TIMEOUT=120s k6 run test.js","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"function connectWithRetry(url, retries = 2) {\n  for (let i = 0; i <= retries; i++) {\n    try {\n      return chromium.connectOverCDP(url);\n    } catch (e) {\n      const m = String(e.message);\n      if (i < retries && m.includes('getting browser target info')) { sleep(3); continue; }\n      throw e;\n    }\n  }\n}","preventionTips":["Ensure the browser container has enough memory/CPU to answer trivial CDP calls","Set K6_BROWSER_TIMEOUT above worst-case setup latency","Capture debug logs for consistent reproductions and report upstream"],"tags":["cdp","internal","setup","timeout","resource-limits"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}