grafana/k6 · error

waitForEvent does not support mapping for event

Error message

waitForEvent does not support mapping for event: %q

What it means

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.

Solutions

  1. Use only the mapped event names: 'console', 'metric', 'request', 'response', 'requestfinished', 'requestfailed'.
  2. For load states use page.waitForLoadState('load' | 'domcontentloaded' | 'networkidle') instead of waitForEvent.
  3. For popups use browserContext.waitForEvent('page'); for navigation use page.waitForNavigation().
  4. For page errors, listen with page.on('console') or wrap script execution in try/catch rather than waitForEvent('pageerror').

Example fix

// before
const popup = await page.waitForEvent('popup');

// after
const popup = await context.waitForEvent('page');
Defensive patterns

Strategy: validation

Validate before calling

const MAPPED_PAGE_EVENTS = new Set(['console', 'metric', 'request', 'response', 'requestfinished', 'requestfailed']);
if (!MAPPED_PAGE_EVENTS.has(event)) throw new Error(`page.waitForEvent cannot map '${event}'; use waitForLoadState/context.waitForEvent instead`);
await page.waitForEvent(event);

Type guard

const isMappedPageEvent = (e) => ['console','metric','request','response','requestfinished','requestfailed'].includes(e);

Try / catch

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; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/ae3df7be34aba89d. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/page_mapping.go:693

			// so that the linter can catch unhandled event types as non-exhaustive switch.
			// Otherwise, we might miss mapping new [PageEvent] types added in the future.
			// This is for keeping events in sync between waitForEvent and page.on.
			mapPageEvent := func(vu moduleVU, pe common.PageEvent) (mapping, error) {
				switch event {
				case common.PageEventConsole:
					return mapConsoleMessage(vu, pe), nil
				case common.PageEventRequest:
					return mapRequestEvent(vu, pe), nil
				case common.PageEventResponse:
					return mapResponseEvent(vu, pe), nil
				case common.PageEventRequestFinished:
					return mapRequestEvent(vu, pe), nil
				case common.PageEventRequestFailed:
					return mapRequestEvent(vu, pe), nil
				case common.PageEventMetric:
					// intentionally left blank
				}
				return nil, fmt.Errorf("waitForEvent does not support mapping for event: %q", event)
			}

			popts, fn, err := parsePageWaitForEventOptions(vu.Context(), opts, p.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing waitForEvent options: %w", err)
			}

			ctx := vu.Context()
			tq := vu.get(ctx, p.TargetID())

			return promise(vu, func() (any, error) {
				rpe, err := p.WaitForEvent(event, popts, func(pe common.PageEvent) (bool, error) {
					if fn == nil {
						return true, nil
					}
					return queueTask(ctx, tq, func() (bool, error) {
						m, err := mapPageEvent(vu, pe)
						if err != nil {

View on GitHub (pinned to 8d06114777)