{"record":{"id":"1407a0ba05fcc8ef","repo":"grafana/k6","slug":"incorrect-event-q-q-is-the-only-event-supported","errorCode":null,"errorMessage":"incorrect event %q, %q is the only event supported","messagePattern":"incorrect event %q, %q is the only event supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":364,"sourceCode":"// Timeout will return the default timeout or the one set by the user.\nfunc (b *BrowserContext) Timeout() time.Duration {\n\treturn b.timeoutSettings.timeout()\n}\n\n// WaitForEvent waits for event.\nfunc (b *BrowserContext) WaitForEvent(event string, f func(p *Page) (bool, error), timeout time.Duration) (any, error) {\n\tb.logger.Debugf(\"BrowserContext:WaitForEvent\", \"bctxid:%v event:%q\", b.id, event)\n\n\treturn b.waitForEvent(waitForEventType(event), f, timeout)\n}\n\nfunc (b *BrowserContext) waitForEvent(\n\tevent waitForEventType,\n\tpredicateFn func(p *Page) (bool, error),\n\ttimeout time.Duration,\n) (any, error) {\n\tif event != waitForEventTypePage {\n\t\treturn nil, fmt.Errorf(\"incorrect event %q, %q is the only event supported\", event, waitForEventTypePage)\n\t}\n\n\tevCancelCtx, evCancelFn := context.WithCancel(b.ctx)\n\tdefer evCancelFn() // This will remove the event handler once we return from here.\n\n\tchEvHandler := make(chan Event)\n\tch := make(chan any)\n\terrCh := make(chan error)\n\n\tgo b.runWaitForEventHandler(evCancelCtx, chEvHandler, predicateFn, ch, errCh)\n\n\tb.on(evCancelCtx, []string{EventBrowserContextPage}, chEvHandler)\n\n\tselect {\n\tcase <-b.ctx.Done():\n\t\treturn nil, ContextErr(b.ctx) //nolint:wrapcheck\n\tcase <-time.After(timeout):\n\t\tb.logger.Debugf(\"BrowserContext:WaitForEvent:timeout\", \"bctxid:%v event:%q\", b.id, event)","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L346-L382","documentation":"BrowserContext.waitForEvent only supports the 'page' event (waitForEventTypePage == 'page'), emitted when a new page is created in the context. Any other event name is rejected immediately by an equality check before any waiting or event wiring happens. This is a smaller surface than Playwright's browser context events.","triggerScenarios":"browserContext.waitForEvent('console'), waitForEvent('close'), waitForEvent('backgroundpage') or any string other than 'page'; passing an undefined/null event variable; event names copied from Playwright's Page event list.","commonSituations":"Porting Playwright scripts and assuming the same event catalog; hoping to wait for console messages or context close via the context object; building the event name dynamically with a typo'd or empty value.","solutions":["Use exactly 'page': ctx.waitForEvent('page', ...) to wait for a new page in the context","For console or page-level events, attach page.on('console') style listeners on individual pages instead of the context","Restructure logic that waits for context lifecycle events other than page creation — k6 does not support them here"],"exampleFix":"// before\nconst page = await ctx.waitForEvent('console'); // only 'page' is supported\n\n// after\nconst page = await ctx.waitForEvent('page');\npage.on('console', (msg) => console.log(msg.text()));","handlingStrategy":"type-guard","validationCode":"const SUPPORTED_CTX_EVENTS = new Set(['page']);\nfunction assertSupportedEvent(event) {\n  if (!SUPPORTED_CTX_EVENTS.has(event)) {\n    throw new Error(`unsupported context event '${event}'; only 'page' is supported`);\n  }\n}\nassertSupportedEvent('page');\nconst p = await ctx.waitForEvent('page');","typeGuard":"const isSupportedContextEvent = (e) => e === 'page';","tryCatchPattern":null,"preventionTips":["Remember the context-level wait supports only the 'page' event in k6","Handle console/page events on Page objects, not on the context","Build event names from constants, not free-form strings"],"tags":["browser","events","wait-for-event","validation"],"backgroundTag":"invalid-event-name","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"}