grafana/k6 · error
incorrect event , is the only event supported
Error message
incorrect event %q, %q is the only event supported
What it means
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.
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
Example fix
// before
const page = await ctx.waitForEvent('console'); // only 'page' is supported
// after
const page = await ctx.waitForEvent('page');
page.on('console', (msg) => console.log(msg.text())); Defensive patterns
Strategy: type-guard
Validate before calling
const SUPPORTED_CTX_EVENTS = new Set(['page']);
function assertSupportedEvent(event) {
if (!SUPPORTED_CTX_EVENTS.has(event)) {
throw new Error(`unsupported context event '${event}'; only 'page' is supported`);
}
}
assertSupportedEvent('page');
const p = await ctx.waitForEvent('page'); Type guard
const isSupportedContextEvent = (e) => e === 'page';
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unknown browser event
- browser.on promise rejected
- cookie name must be set: %#v
- cookie value must be set: %#v
- default browser context can't be closed
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/1407a0ba05fcc8ef.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/browser_context.go:364
// Timeout will return the default timeout or the one set by the user.
func (b *BrowserContext) Timeout() time.Duration {
return b.timeoutSettings.timeout()
}
// WaitForEvent waits for event.
func (b *BrowserContext) WaitForEvent(event string, f func(p *Page) (bool, error), timeout time.Duration) (any, error) {
b.logger.Debugf("BrowserContext:WaitForEvent", "bctxid:%v event:%q", b.id, event)
return b.waitForEvent(waitForEventType(event), f, timeout)
}
func (b *BrowserContext) waitForEvent(
event waitForEventType,
predicateFn func(p *Page) (bool, error),
timeout time.Duration,
) (any, error) {
if event != waitForEventTypePage {
return nil, fmt.Errorf("incorrect event %q, %q is the only event supported", event, waitForEventTypePage)
}
evCancelCtx, evCancelFn := context.WithCancel(b.ctx)
defer evCancelFn() // This will remove the event handler once we return from here.
chEvHandler := make(chan Event)
ch := make(chan any)
errCh := make(chan error)
go b.runWaitForEventHandler(evCancelCtx, chEvHandler, predicateFn, ch, errCh)
b.on(evCancelCtx, []string{EventBrowserContextPage}, chEvHandler)
select {
case <-b.ctx.Done():
return nil, ContextErr(b.ctx) //nolint:wrapcheck
case <-time.After(timeout):
b.logger.Debugf("BrowserContext:WaitForEvent:timeout", "bctxid:%v event:%q", b.id, event)View on GitHub (pinned to 01ffac6f24)