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
- Use exactly 'load', 'domcontentloaded', or 'networkidle'
- Read the wrapped cause — it enumerates valid values
- 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
- Share one constant list of lifecycle values across goto and setContent
- The DOM event is 'DOMContentLoaded' but the option value is lowercase 'domcontentloaded'
- Default waitUntil is 'load' — omit it unless you need otherwise
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
- parsing frame navigation options to
- an error occurred communicating with k6 Cloud
- " " attribute is only supported for roles: "`).join(", ")}
- " " does not support " " matcher
- " " must be one of
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:wrapcheckView on GitHub (pinned to 8d06114777)