{"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/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L346-L382","documentation":"Thrown by BrowserContext.waitForEvent when the requested event name is not the single supported value. The internal waitForEventType comparison only accepts waitForEventTypePage (\"page\"); any other string (or a mistyped variant) is rejected immediately, before any waiting starts. This mirrors the fact that the k6 browser context API only implements the page-creation event.","triggerScenarios":"Calling browserContext.waitForEvent('console'), 'close', 'pageopen', 'Page', or any string other than exactly 'page'. The check happens up front, so the error is deterministic and unrelated to timing or browser state.","commonSituations":"Developers copying Playwright examples that wait for events like 'console' or 'backgroundpage' which k6's browser context does not support; capitalization or spelling mistakes such as 'Page' or 'newpage'; assuming the full Playwright event surface exists in k6.","solutions":["Use the only supported event: browserContext.waitForEvent('page').","For other events, use the page-level API instead, e.g. page.waitForEvent('console') or page.waitForEvent('popup') on a Page object.","If you truly need context-level events beyond 'page', file a feature request or use a k6 browser extension; there is no workaround parameter."],"exampleFix":"// before\nconst ctx = browser.newContext();\nctx.waitForEvent('console'); // throws\n\n// after\nconst ctx = browser.newContext();\nctx.waitForEvent('page'); // supported\n// or, for console messages, go through a page:\nconst page = ctx.newPage();\npage.on('console', (msg) => console.log(msg.text()));","handlingStrategy":"validation","validationCode":"const SUPPORTED_CONTEXT_EVENTS = new Set(['page']);\nfunction assertSupportedContextEvent(event) {\n  if (!SUPPORTED_CONTEXT_EVENTS.has(event)) {\n    throw new Error(\n      `unsupported context event \"${event}\"; only \"page\" is supported, use page.waitForEvent for other events`\n    );\n  }\n}\nassertSupportedContextEvent(event);\ncontext.waitForEvent(event);","typeGuard":"function isSupportedContextEvent(event) {\n  return event === 'page';\n}","tryCatchPattern":null,"preventionTips":["Remember k6's context-level waitForEvent supports only 'page'; everything else is a page-level API.","Centralize event names in constants to avoid typos.","Don't port Playwright context-event examples verbatim."],"tags":["events","api-misuse","browser-context","waitfor"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}