{"record":{"id":"e70a0ac2b68d5407","repo":"grafana/k6","slug":"on-create-page-event-failed-to-return-a-page-w","errorCode":null,"errorMessage":"on create page event failed to return a page: %w","messagePattern":"on create page event failed to return a page: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":421,"sourceCode":"\tdefer func() {\n\t\tclose(out)\n\t\tclose(errOut)\n\t}()\n\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\tb.logger.Debugf(\"BrowserContext:runWaitForEventHandler:go():ctx:done\", \"bctxid:%v\", b.id)\n\t\t\treturn\n\t\tcase ev := <-chEvHandler:\n\t\t\tif ev.typ != EventBrowserContextPage {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tb.logger.Debugf(\"BrowserContext:runWaitForEventHandler:go():EventBrowserContextPage\", \"bctxid:%v\", b.id)\n\t\t\tp, ok := ev.data.(*Page)\n\t\t\tif !ok {\n\t\t\t\terrOut <- fmt.Errorf(\"on create page event failed to return a page: %w\", k6error.ErrFatal)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif predicateFn == nil {\n\t\t\t\tb.logger.Debugf(\"BrowserContext:runWaitForEventHandler:go():EventBrowserContextPage:return\", \"bctxid:%v\", b.id)\n\t\t\t\tout <- p\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tretVal, err := predicateFn(p)\n\t\t\tif err != nil {\n\t\t\t\terrOut <- fmt.Errorf(\"predicate function failed: %w\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif retVal {\n\t\t\t\tb.logger.Debugf(\n\t\t\t\t\t\"BrowserContext:runWaitForEventHandler:go():EventBrowserContextPage:predicateFn:return\",","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L403-L439","documentation":"Internal invariant error from BrowserContext.runWaitForEventHandler: when the 'page' event fired, its payload could not be asserted to a *Page, so the handler wraps k6error.ErrFatal and ships it to the error channel of waitForEvent. ErrFatal marks unrecoverable failures in k6 and aborts the iteration; in practice this path should never execute because the event source always emits a *Page.","triggerScenarios":"Only reachable if the internal event emitter dispatches an EventBrowserContextPage whose data is not a *Page — i.e. a bug or an unexpected internal state in k6's browser module. No user input can produce it directly.","commonSituations":"Essentially never seen in normal use; if it appears, it is after upgrading to a k6 version with a regression in the browser event dispatch code, or in a custom build/extension that emits context events with the wrong payload type.","solutions":["Upgrade (or roll back) k6 to a version where the browser module event dispatch is stable.","Report it as a bug to k6 (https://github.com/grafana/k6/issues) including the script and debug logs, since it indicates an internal invariant violation.","As a workaround, poll for new pages via context.pages() on a timer instead of waitForEvent."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const page = await context.waitForEvent('page');\n} catch (e) {\n  if (e.message.includes('failed to return a page')) {\n    // internal fatal invariant: abort and report a k6 bug with debug logs\n    throw new Error(`k6 internal error, please report: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Keep k6 updated to a stable release of the browser module.","Capture debug logs (--log-output=file=debug.log with DEBUG level) so internal failures are diagnosable.","Treat this error as a bug report, not a script problem."],"tags":["internal","fatal","events","browser-context"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}