{"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":"panic","errorClass":"ErrFatal","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/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L403-L439","documentation":"Internal invariant violation: a 'page' event fired on the context but its payload failed the type assertion to *Page, so the handler reports it wrapped with k6error.ErrFatal. In k6, ErrFatal marks the browser module as unusable and aborts the current iteration — it is not a user-input error. Realistically this only occurs from a k6 bug or corrupted internal state.","triggerScenarios":"Not reproducible from script code: it requires the internal event dispatch to publish a non-Page payload as EventBrowserContextPage. Seen, if ever, on development or edge builds of k6 with mismatched internal types.","commonSituations":"Custom/nightly k6 builds; extremely rare races in event dispatch; never in normal scripted usage.","solutions":["Upgrade to the latest stable k6 release","If it persists on the latest version, report it at github.com/grafana/k6/issues with the script, k6 version, and browser logs","There is no script-level fix — treat the browser/context as unusable and let the iteration restart fresh"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// fatal internal error: iteration cannot continue with this browser; let it fail and report\ntry {\n  const p = await ctx.waitForEvent('page');\n} catch (e) {\n  if (String(e.message).includes('failed to return a page')) {\n    throw new Error(`k6 internal fatal error, please report: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Run the latest stable k6 — internal dispatch bugs get fixed in releases","Pin k6 versions in CI so a bad build cannot silently appear","Keep the script + k6 version ready to attach when reporting internal fatal errors"],"tags":["browser","internal","fatal","type-assertion"],"backgroundTag":"internal-type-assertion-failure","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"}