{"record":{"id":"185a1a5fc9941dc1","repo":"grafana/k6","slug":"closing-a-page-w","errorCode":null,"errorMessage":"closing a page: %w","messagePattern":"closing a page: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":1026,"sourceCode":"\n\t\tadd := runtime.RemoveBinding(webVitalBinding)\n\t\tif err := add.Do(cdp.WithExecutor(teardownTimeoutCtx, p.session)); err != nil {\n\t\t\t// continue so that we can shutdown the page even if we fail to remove the binding.\n\t\t\tcloseErrs = append(closeErrs, fmt.Errorf(\"internal error while removing binding from page: %w\", err))\n\t\t}\n\n\t\terr := target.CloseTarget(p.targetID).Do(cdp.WithExecutor(teardownTimeoutCtx, p.session))\n\t\tif err != nil && !errors.Is(err, context.Canceled) {\n\t\t\t// When a close target command is sent to the browser via CDP,\n\t\t\t// the browser will start to cleanup and the first thing it\n\t\t\t// will do is return a target.EventDetachedFromTarget, which in\n\t\t\t// our implementation will close the session connection (this\n\t\t\t// does not close the CDP websocket, just removes the session\n\t\t\t// so no other CDP calls can be made with the session ID).\n\t\t\t// This can result in the session's context being closed while\n\t\t\t// we're waiting for the response to come back from the browser\n\t\t\t// for this current command (it's racey).\n\t\t\tcloseErrs = append(closeErrs, fmt.Errorf(\"closing a page: %w\", err))\n\t\t}\n\n\t\t// Start the teardown of the page's resources (FrameSessions, NetworkManagers, etc)\n\t\t// and wait for them to finish their teardown. This allows for a graceful cleanup\n\t\t// of resources and ensures that all events are processed before the page is closed.\n\t\tp.cancelCtx()\n\t\tp.waitForFrameSessions()\n\n\t\tif len(closeErrs) > 0 {\n\t\t\tp.closeErr = spanRecordError(span, errors.Join(closeErrs...))\n\t\t}\n\t})\n\n\treturn p.closeErr\n}\n\n// Content returns the HTML content of the page.\nfunc (p *Page) Content() (string, error) {","sourceCodeStart":1008,"sourceCodeEnd":1044,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/page.go#L1008-L1044","documentation":"Failure of the CDP target.closeTarget command during page close. Context-canceled errors are ignored (the browser is already shutting down and the close response may race); other failures — e.g. the target is already closed or the session died — are collected into closeErrs and surfaced after teardown completes.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/page.go:1021 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Usually benign when the browser/context is already closing; inspect the wrapped error","Avoid closing the same page twice","Ensure the browser process is healthy if closes consistently fail"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}