{"record":{"id":"2dc3fe45f8789b2f","repo":"grafana/k6","slug":"run-if-waiting-for-debugger-to-attach-w","errorCode":null,"errorMessage":"run if waiting for debugger to attach: %w","messagePattern":"run if waiting for debugger to attach: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":129,"sourceCode":"\t\tteardownCtx:          teardownCtx,\n\t\tsession:              s,\n\t\tpage:                 p,\n\t\tparent:               parent,\n\t\tmanager:              p.frameManager,\n\t\ttargetID:             tid,\n\t\tcontextIDToContextMu: sync.Mutex{},\n\t\tcontextIDToContext:   make(map[cdpruntime.ExecutionContextID]*ExecutionContext),\n\t\tisolatedWorlds:       make(map[string]bool),\n\t\teventCh:              make(chan Event),\n\t\tchildSessions:        make(map[cdp.FrameID]*FrameSession),\n\t\tvu:                   k6ext.GetVU(ctx),\n\t\tk6Metrics:            k6Metrics,\n\t\tlogger:               l,\n\t\thasUIWindow:          hasUIWindow,\n\t}\n\n\tif err := cdpruntime.RunIfWaitingForDebugger().Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\treturn nil, fmt.Errorf(\"run if waiting for debugger to attach: %w\", err)\n\t}\n\n\tvar parentNM *NetworkManager\n\tif fs.parent != nil {\n\t\tparentNM = fs.parent.networkManager\n\t}\n\tfs.networkManager, err = NewNetworkManager(ctx, k6Metrics, s, fs.manager, parentNM, fs.manager.page)\n\tif err != nil {\n\t\tl.Debugf(\"NewFrameSession:NewNetworkManager\", \"sid:%v tid:%v err:%v\",\n\t\t\ts.ID(), tid, err)\n\t\treturn nil, err\n\t}\n\n\t// When a frame creates a new FrameSession without UI (e.g. some iframes) we cannot\n\t// retrieve the windowID. Doing so would lead to an error from chromium. For now all\n\t// iframes that are attached are setup with hasUIWindow as false which seems to work\n\t// as expected for iframes with and without UI elements.\n\tif fs.hasUIWindow {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L111-L147","documentation":"During FrameSession construction (frame_session.go:129), k6 sends the CDP command Runtime.runIfWaitingForDebugger immediately after attaching to a target. If the command fails, the new frame session is abandoned with this wrapped error. Failure almost never means a debugger setting problem — it means the CDP session or target is already unusable (browser crashed, was killed, or the connection dropped).","triggerScenarios":"Opening a page/new target at the exact moment chromium dies (OOM kill, crash), a remote browser (K6_BROWSER_WS_URL) that closes the session mid-attach, or a CDP endpoint/proxy with protocol version incompatibilities.","commonSituations":"Headless chromium killed by the OOM killer in memory-capped CI containers, k6 pointing at a wrong or flaky remote CDP endpoint, or browsers older/newer than the k6 build expects.","solutions":["Check whether chromium died: look for OOM kills (dmesg | grep -i oom), raise container memory limits or lower VU/page counts","Verify the browser endpoint and settings (K6_BROWSER_WS_URL, K6_BROWSER_HEADLESS); reproduce with a local bundled chromium to rule out the remote","Upgrade k6 (and the chromium it drives) so CDP domains match; rerun — transient crashes at attach are common under load"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const page = browser.newPage();\n} catch (e) {\n  if (/run if waiting for debugger/i.test(String(e))) {\n    // chromium died at attach — recreate context/page once after a short pause\n  }\n}","preventionTips":["Give chromium enough memory (containers: raise limits, lower VU/page concurrency)","Recreate the browser context when page creation fails rather than failing the whole run","Pin a chromium build known to work with your k6 version"],"tags":["browser","cdp","session","crash","infrastructure"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}