grafana/k6 · error

parsing waitForRequest options

Error message

parsing waitForRequest options: %w

What it means

Thrown by page.waitForRequest(url, opts) in the k6 browser module when the opts argument cannot be parsed. parsePageWaitForRequestOptions only recognizes the 'timeout' key (integer milliseconds); any other key in the object is rejected and wrapped in this error.

Solutions

  1. Use only { timeout: <milliseconds> } as the second argument, or omit it to inherit page.setTimeout()/default timeout.
  2. To match more than a URL, pass a RegExp as the first argument instead of adding option keys.
  3. Remove Playwright-only keys (headers, method, predicate) from the options object.
  4. Configure the default action timeout once via browser.newContext({ actionTimeout }) so per-call options are unnecessary.

Example fix

// before
const req = await page.waitForRequest('**/submit', { method: 'POST', timeout: 5000 });

// after
const req = await page.waitForRequest('**/submit', { timeout: 5000 });
Defensive patterns

Strategy: validation

Validate before calling

const opts = { timeout: 5000 };
const unknown = Object.keys(opts).filter(k => k !== 'timeout');
if (unknown.length) throw new Error(`unsupported waitForRequest keys: ${unknown.join(', ')}`);
await page.waitForRequest('**/login', opts);

Type guard

const isWaitForRequestOpts = (o) => o == null || (typeof o === 'object' && Object.keys(o).every(k => k === 'timeout'));

Try / catch

try { await page.waitForRequest(url, opts); } catch (e) { if (e.message.includes('parsing waitForRequest options')) { /* fix opts and retry once */ } throw e; }

Prevention

When it happens

Trigger: Calling page.waitForRequest('/api/login', { headers: {...} }), or any second argument object containing keys besides 'timeout'. Passing options designed for http.post (headers, auth) instead of the wait API also triggers it.

Common situations: Assuming waitForRequest accepts request-shaping options (headers, method) like Playwright's page.waitForRequest(urlOrPredicate, options) does not; copying options from waitForFunction or waitForLoadState; typos such as {timeoutms: 5000}.

Related errors


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

Appendix: source

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

			var val string
			switch url.ExportType() {
			case reflect.TypeFor[string]():
				val = "'" + url.String() + "'" // Strings require quotes
			default: // JS Regex, CSS, numbers or booleans
				val = url.String() // No quotes
			}

			tq, ctx, stop := newTaskQueue(vu)

			return promise(vu, func() (result any, reason error) {
				defer stop()
				return p.WaitForResponse(val, popts, newRegExMatcher(ctx, vu, tq))
			}), nil
		},
		"waitForRequest": func(url sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parsePageWaitForRequestOptions(vu.Context(), opts, p.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing waitForRequest options: %w", err)
			}

			var val string
			switch url.ExportType() {
			case reflect.TypeFor[string]():
				val = "'" + url.String() + "'" // Strings require quotes
			default: // JS Regex, CSS, numbers or booleans
				val = url.String() // No quotes
			}

			tq, ctx, stop := newTaskQueue(vu)

			return promise(vu, func() (result any, reason error) {
				defer stop()
				return p.WaitForRequest(val, popts, newRegExMatcher(ctx, vu, tq))
			}), nil
		},
		"waitForEvent": func(event common.PageEventName, opts sobek.Value) (*sobek.Promise, error) {

View on GitHub (pinned to 8d06114777)