{"record":{"id":"ae3df7be34aba89d","repo":"grafana/k6","slug":"waitforevent-does-not-support-mapping-for-event","errorCode":null,"errorMessage":"waitForEvent does not support mapping for event: %q","messagePattern":"waitForEvent does not support mapping for event: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":693,"sourceCode":"\t\t\t// so that the linter can catch unhandled event types as non-exhaustive switch.\n\t\t\t// Otherwise, we might miss mapping new [PageEvent] types added in the future.\n\t\t\t// This is for keeping events in sync between waitForEvent and page.on.\n\t\t\tmapPageEvent := func(vu moduleVU, pe common.PageEvent) (mapping, error) {\n\t\t\t\tswitch event {\n\t\t\t\tcase common.PageEventConsole:\n\t\t\t\t\treturn mapConsoleMessage(vu, pe), nil\n\t\t\t\tcase common.PageEventRequest:\n\t\t\t\t\treturn mapRequestEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventResponse:\n\t\t\t\t\treturn mapResponseEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventRequestFinished:\n\t\t\t\t\treturn mapRequestEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventRequestFailed:\n\t\t\t\t\treturn mapRequestEvent(vu, pe), nil\n\t\t\t\tcase common.PageEventMetric:\n\t\t\t\t\t// intentionally left blank\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"waitForEvent does not support mapping for event: %q\", event)\n\t\t\t}\n\n\t\t\tpopts, fn, err := parsePageWaitForEventOptions(vu.Context(), opts, p.Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing waitForEvent options: %w\", err)\n\t\t\t}\n\n\t\t\tctx := vu.Context()\n\t\t\ttq := vu.get(ctx, p.TargetID())\n\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\trpe, err := p.WaitForEvent(event, popts, func(pe common.PageEvent) (bool, error) {\n\t\t\t\t\tif fn == nil {\n\t\t\t\t\t\treturn true, nil\n\t\t\t\t\t}\n\t\t\t\t\treturn queueTask(ctx, tq, func() (bool, error) {\n\t\t\t\t\t\tm, err := mapPageEvent(vu, pe)\n\t\t\t\t\t\tif err != nil {","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/page_mapping.go#L675-L711","documentation":"Thrown by page.waitForEvent(eventName, opts) when the event that arrived (or that the wait resolved with) has no Go-to-JS mapping. The mapping switch in mapPageEvent only covers console, metric, request, response, requestfinished and requestfailed; any other event name reaches the default branch and produces this error.","triggerScenarios":"Calling page.waitForEvent('popup'), 'load', 'domcontentloaded', 'close', 'download', 'filechooser', 'pageerror', or 'crash' — names that exist in Playwright but have no case in the k6 mapPageEvent switch. The error fires when the event is delivered to the mapper (inside the predicate or on resolution).","commonSituations":"Porting Playwright test scripts verbatim; using lifecycle events ('load', 'domcontentloaded') with waitForEvent instead of waitForLoadState; expecting dialog or download support that the k6 browser module does not map.","solutions":["Use only the mapped event names: 'console', 'metric', 'request', 'response', 'requestfinished', 'requestfailed'.","For load states use page.waitForLoadState('load' | 'domcontentloaded' | 'networkidle') instead of waitForEvent.","For popups use browserContext.waitForEvent('page'); for navigation use page.waitForNavigation().","For page errors, listen with page.on('console') or wrap script execution in try/catch rather than waitForEvent('pageerror')."],"exampleFix":"// before\nconst popup = await page.waitForEvent('popup');\n\n// after\nconst popup = await context.waitForEvent('page');","handlingStrategy":"validation","validationCode":"const MAPPED_PAGE_EVENTS = new Set(['console', 'metric', 'request', 'response', 'requestfinished', 'requestfailed']);\nif (!MAPPED_PAGE_EVENTS.has(event)) throw new Error(`page.waitForEvent cannot map '${event}'; use waitForLoadState/context.waitForEvent instead`);\nawait page.waitForEvent(event);","typeGuard":"const isMappedPageEvent = (e) => ['console','metric','request','response','requestfinished','requestfailed'].includes(e);","tryCatchPattern":"try { await page.waitForEvent(name, opts); } catch (e) { if (e.message.includes('does not support mapping for event')) { /* switch to a supported API for this event */ } throw e; }","preventionTips":["Maintain a whitelist constant of the six mapped page events and assert against it before waitForEvent calls.","Map lifecycle needs to waitForLoadState and popup needs to context.waitForEvent during Playwright porting."],"tags":["k6","browser","page","waitforevent","events","unsupported-feature"],"backgroundTag":"unsupported-event-name","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}