{"record":{"id":"e475d4f5d0772158","repo":"grafana/k6","slug":"lost-connection-while-closing-the-browser-websock","errorCode":null,"errorMessage":"lost connection while closing the browser (websocket url: %s)","messagePattern":"lost connection while closing the browser \\(websocket url: (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_process.go","lineNumber":105,"sourceCode":"\t}\n\n\tgo p.handleClose(ctx)\n\n\treturn &p, nil\n}\n\nfunc (p *BrowserProcess) handleClose(ctx context.Context) {\n\t// If we lose connection to the browser and we're not in-progress with clean\n\t// browser-initiated termination then cancel the context to clean up.\n\tselect {\n\tcase <-p.lostConnection:\n\tcase <-ctx.Done():\n\t}\n\n\tselect {\n\tcase <-p.processIsGracefullyClosing:\n\tdefault:\n\t\tp.cancel(fmt.Errorf(\"lost connection while closing the browser (websocket url: %s)\", p.wsURL))\n\t}\n}\n\nfunc (p *BrowserProcess) didLoseConnection() {\n\tclose(p.lostConnection)\n}\n\nfunc (p *BrowserProcess) isConnected() bool {\n\tvar ok bool\n\tselect {\n\tcase _, ok = <-p.lostConnection:\n\tdefault:\n\t\tok = true\n\t}\n\treturn ok\n}\n\n// GracefulClose triggers a graceful closing of the browser process.","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_process.go#L87-L123","documentation":"BrowserProcess.handleClose detected that the CDP WebSocket connection to the browser was lost while the process was not in a graceful, browser-initiated shutdown. To clean up, the process cancels the iteration context with this error, including the lost WebSocket URL.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/browser_process.go:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Investigate why the browser crashed or disconnected (OOM, crash, container eviction)","Avoid killing the browser process from outside the test","Handle the aborted iteration in the script or CI and re-run"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}