grafana/k6 · error

parsing setContent options

Error message

parsing setContent options: %w

What it means

Thrown when `frame.setContent(html, opts)` options fail to parse into FrameSetContentOptions. Keys: `timeout` (ms, coercive) and `waitUntil` — a strict enum accepting exactly 'load', 'domcontentloaded', or 'networkidle' (validated by LifecycleEvent.UnmarshalText, whose error lists all valid values). An invalid waitUntil is the only real trigger.

Solutions

  1. Use exactly 'load', 'domcontentloaded', or 'networkidle'
  2. Read the wrapped cause — it enumerates valid values
  3. Default is 'load'; omit waitUntil if that is what you want

Example fix

// before
await frame.setContent(html, { waitUntil: 'DOMContentLoaded' });

// after
await frame.setContent(html, { waitUntil: 'domcontentloaded' });
Defensive patterns

Strategy: validation

Validate before calling

const WAIT_UNTIL = new Set(['load', 'domcontentloaded', 'networkidle']);
function assertSetContentOpts(opts = {}) {
  if (opts.waitUntil !== undefined && !WAIT_UNTIL.has(opts.waitUntil)) {
    throw new Error(`waitUntil must be one of: ${[...WAIT_UNTIL].join(', ')}`);
  }
}

Type guard

function isValidLifecycleEvent(v) {
  return v === 'load' || v === 'domcontentloaded' || v === 'networkidle';
}

Try / catch

try {
  await frame.setContent(html, opts);
} catch (e) {
  if (/parsing setContent options.*invalid lifecycle event/.test(String(e))) {
    throw new Error('Bad waitUntil for setContent; use load|domcontentloaded|networkidle');
  }
  throw e;
}

Prevention

When it happens

Trigger: `frame.setContent('<p>hi</p>', { waitUntil: 'DOMContentLoaded' })`, `{ waitUntil: 'load ' }` (trailing space), or any string not in the enum; the underlying error is "invalid lifecycle event: %q; must be one of: domcontentloaded, load, networkidle".

Common situations: CamelCase lifecycle names copied from browser event docs ('DOMContentLoaded' mirrors the DOM event, not k6's option value); Playwright scripts using newer lifecycle names not supported here.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of grafana/k6@8d06114777 (2026-09-14). Data as JSON: /api/errors/6f29bac53b5f6721. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/frame_mapping.go:358

			return promise(vu, func() (any, error) {
				return f.SelectOption(selector, convValues, popts) //nolint:wrapcheck
			}), nil
		},
		"setChecked": func(selector string, checked bool, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseFrameCheckOptions(rt, opts, f.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing frame set check options: %w", err)
			}

			return promise(vu, func() (any, error) {
				return nil, f.SetChecked(selector, checked, popts) //nolint:wrapcheck
			}), nil
		},
		"setContent": func(html string, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseFrameSetContentOptions(rt, opts, f.Page().NavigationTimeout())
			if err != nil {
				return nil, fmt.Errorf("parsing setContent options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, f.SetContent(html, popts) //nolint:wrapcheck
			}), nil
		},
		"setInputFiles": func(selector string, files sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseFrameSetInputFilesOptions(rt, opts, f.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing setInputFiles options: %w", err)
			}

			pfiles := new(common.Files)
			if err := pfiles.Parse(vu.Context(), files); err != nil {
				return nil, fmt.Errorf("parsing setInputFiles parameter: %w", err)
			}

			return promise(vu, func() (any, error) {
				return nil, f.SetInputFiles(selector, pfiles, popts) //nolint:wrapcheck

View on GitHub (pinned to 8d06114777)