{"record":{"id":"b831f9e63043b93f","repo":"grafana/k6","slug":"browser-closed","errorCode":null,"errorMessage":"browser closed","messagePattern":"browser closed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser.go","lineNumber":583,"sourceCode":"\t\t\tErr: errors.New(\"can't fetch the page for unknown reason\"),\n\t\t}\n\t}\n\n\treturn page, err\n}\n\n// Close shuts down the browser.\nfunc (b *Browser) Close() {\n\tif !b.closing.CompareAndSwap(false, true) {\n\t\tb.logger.Warnf(\n\t\t\t\"Browser:Close\",\n\t\t\t\"Please call browser.close only once, and do not use the browser after calling close.\",\n\t\t)\n\t\treturn\n\t}\n\t// This will help with some cleanup in the connection and event loop above in\n\t// initEvents().\n\tdefer b.browserCancelFn(errors.New(\"browser closed\"))\n\tdefer func() {\n\t\tif err := b.browserProc.Cleanup(); err != nil {\n\t\t\tb.logger.Errorf(\"Browser:Close\", \"cleaning up the user data directory: %v\", err)\n\t\t}\n\t}()\n\tdefer func() {\n\t\tfor _, fn := range b.runOnClose {\n\t\t\tif err := fn(); err != nil {\n\t\t\t\tb.logger.Errorf(\"Browser:Close\", \"running cleanup function: %v\", err)\n\t\t\t}\n\t\t}\n\t}()\n\t// Close and drain all open pages to ensure their goroutines\n\t// (frame sessions, network managers) are properly waited on\n\t// before the browser process is terminated.\n\tfor _, p := range b.getPages() {\n\t\tif err := p.Close(); err != nil {\n\t\t\tb.logger.Debugf(\"Browser:Close\", \"closing page: %v\", err)","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/js/modules/k6/browser/common/browser.go#L565-L601","documentation":"Browser.Close uses this sentinel error as the cancellation reason passed to browserCancelFn when shutting down the browser. It is the normal shutdown signal propagated through the context so all pending CDP operations and goroutines terminate promptly; seeing it usually just means the browser was closed while work was in flight.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/browser.go:582 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Treat as expected during shutdown; ensure browser.close() is called once and the browser isn't used afterwards","Structure scripts so no browser operations race the final close","Ignore or log at debug level if seen right after browser.close()"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}