{"record":{"id":"e900b0e74a00b938","repo":"grafana/k6","slug":"internal-error-while-removing-binding-from-page","errorCode":null,"errorMessage":"internal error while removing binding from page: %w","messagePattern":"internal error while removing binding from page: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":1012,"sourceCode":"\t\t\tObject.defineProperty(document, 'visibilityState', {value: 'hidden', configurable: true});\n\t\t\tObject.defineProperty(document, 'hidden', {value: true, configurable: true});\n\t\t\tdocument.dispatchEvent(new Event('visibilitychange'));\n\t\t}`\n\t\tif _, err := p.MainFrame().EvaluateWithContext(teardownTimeoutCtx, v); err != nil {\n\t\t\tp.logger.Warnf(\"Page:Close\", \"failed to trigger visibilitychange for web vitals: %v\", err)\n\t\t}\n\n\t\tkeyDown := input.DispatchKeyEvent(input.KeyDown).WithKey(\"Escape\")\n\t\tif err := keyDown.Do(cdp.WithExecutor(teardownTimeoutCtx, p.session)); err != nil {\n\t\t\tp.logger.Warnf(\"Page:Close\", \"failed to dispatch keydown for web vitals: %v\", err)\n\t\t}\n\n\t\tvar closeErrs []error\n\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","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/page.go#L994-L1030","documentation":"Failure of the CDP runtime.removeBinding command during page close while removing the web-vitals binding. Deliberately non-fatal: the error is appended to closeErrs and shutdown continues, because teardown must proceed even if the binding cannot be removed.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/page.go:1007 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Treat as non-fatal — page close proceeds regardless","Occurs mostly when the target is already gone; no action needed","Report only if it accompanies other consistent close failures"],"exampleFix":null,"handlingStrategy":"fallback","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"}