grafana/k6 · error
is not a valid lifecycle
Error message
%q is not a valid lifecycle
What it means
Thrown while parsing page navigation options (PageGotoOptions.Parse) when the waitUntil value is not one of the supported lifecycle names. The parser looks the string up in lifecycleEventToID, which only contains 'load', 'domcontentloaded', and 'networkidle'; anything else is rejected with this quoted-value error. Note Playwright-style values like 'commit' or 'domcontentloaded ' (typo/case) are not supported.
Solutions
- Use one of: 'load', 'domcontentloaded', 'networkidle'.
- Fix case and spelling — the value is matched exactly, lowercase only.
- Replace 'networkidle2' with 'networkidle', and drop Playwright-only 'commit'.
Example fix
// before
await page.goto(url, { waitUntil: 'networkidle2' });
// after
await page.goto(url, { waitUntil: 'networkidle' }); Defensive patterns
Strategy: validation
Validate before calling
const LIFECYCLES = ['load', 'domcontentloaded', 'networkidle'];
if (!LIFECYCLES.includes(waitUntil)) throw new Error(`waitUntil must be one of ${LIFECYCLES.join(', ')}`);
await page.goto(url, { waitUntil }); Type guard
const isLifecycle = (v) => v === 'load' || v === 'domcontentloaded' || v === 'networkidle';
Prevention
- Define the three valid values as script constants and reuse them.
- When porting Playwright/Puppeteer scripts, map 'commit'→'domcontentloaded', 'networkidle2'→'networkidle'.
- Values are case-sensitive; always lowercase.
When it happens
Trigger: Calling page.goto(url, { waitUntil: 'commit' | 'domContentLoaded' | 'interactive' }) or any non-enum string; copying scripts from Playwright/Puppeteer docs that use lifecycle names k6 does not implement; passing an empty string or wrong case ('Load').
Common situations: Migrating Playwright tests to k6 browser (Playwright adds 'commit'); typos and case mismatches; assuming Puppeteer's 'networkidle2' exists — k6 only supports 'networkidle'.
Related errors
- page.route(' '): iteration ended before route completed
- an error occurred communicating with k6 Cloud
- an error occurred communicating with the provisioning API
- " " attribute is only supported for roles: "`).join(", ")}
- " " does not support " " matcher
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/04db8e3b6924e483.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/page_options.go:81
Timeout: defaultTimeout,
}
}
// Parse parses the page go back/forward options.
func (o *PageGoBackForwardOptions) Parse(ctx context.Context, opts sobek.Value) error {
if common.IsNullish(opts) {
return nil
}
obj := opts.ToObject(k6ext.Runtime(ctx))
for _, k := range obj.Keys() {
switch k {
case "waitUntil":
lifeCycle := obj.Get(k).String()
if l, ok := lifecycleEventToID[lifeCycle]; ok {
o.WaitUntil = l
} else {
return fmt.Errorf("%q is not a valid lifecycle", lifeCycle)
}
case "timeout":
o.Timeout = time.Duration(obj.Get(k).ToInteger()) * time.Millisecond
}
}
return nil
}
// Parse parses the page reload options.
func (o *PageReloadOptions) Parse(ctx context.Context, opts sobek.Value) error {
rt := k6ext.Runtime(ctx)
if !common.IsNullish(opts) {
opts := opts.ToObject(rt)
for _, k := range opts.Keys() {
switch k {
case "waitUntil":
lifeCycle := opts.Get(k).String()View on GitHub (pinned to 01ffac6f24)