grafana/k6 · error
unknown browser event: %q, must be %q
Error message
unknown browser event: %q, must be %q
What it means
Browser.On (browser.go:773) accepts exactly one event name — "disconnected" (EventBrowserDisconnected). Any other string passed to browser.on(event) fails immediately with 'unknown browser event: %q, must be "disconnected"' before any waiting starts. This is a fail-fast API-misuse error, not an environment problem.
Source
Thrown at internal/js/modules/k6/browser/common/browser.go:773
browserCtx, err := b.NewContext(opts)
if err != nil {
return nil, spanRecordErrorf(span, "new page: %w", err)
}
page, err := browserCtx.NewPage()
if err != nil {
return nil, spanRecordError(span, err)
}
return page, nil
}
// On returns a Promise that is resolved when the browser process is disconnected.
// The only accepted event value is "disconnected".
func (b *Browser) On(event string) (bool, error) {
if event != EventBrowserDisconnected {
return false, fmt.Errorf("unknown browser event: %q, must be %q", event, EventBrowserDisconnected)
}
select {
case <-b.browserProc.lostConnection:
return true, nil
case <-b.vuCtx.Done():
return false, fmt.Errorf("browser.on promise rejected: %w", ContextErr(b.vuCtx))
}
}
// UserAgent returns the controlled browser's user agent string.
func (b *Browser) UserAgent() string {
return b.version.userAgent
}
// Version returns the controlled browser's version.
func (b *Browser) Version() string {
product := b.version.productView on GitHub (pinned to 93accf6570)
Solutions
- Use exactly browser.on('disconnected') — the only supported event
- Check the event name is a literal 'disconnected' before calling if it comes from a variable/config
- Use a linter/constant in shared test helpers so the name cannot drift
Example fix
// before
await browser.on('close') // throws: unknown browser event
// after
await browser.on('disconnected') Defensive patterns
Strategy: validation
Validate before calling
const eventName = 'disconnected'
if (eventName !== 'disconnected') {
throw new Error(`unsupported event: ${eventName}`)
}
await browser.on(eventName) Type guard
function isBrowserEvent(e) {
return e === 'disconnected'
} Prevention
- browser.on supports exactly one event: 'disconnected'
- Keep the event name as a module-level constant in shared helpers
- Do not port other Playwright browser event names
When it happens
Trigger: Calling browser.on('close'), browser.on('disconnected ') with whitespace/case differences, or any invented event name; passing a variable that is undefined or an empty string.
Common situations: Porting Playwright code that uses browser.on('disconnected') together with other event names; copy-paste from EventEmitter-style APIs; typos and case errors.
Related errors
- predicate function is not callable
- iteration ended before page.on handler completed executing
- "handler" argument cannot be nil
- clip area is either empty or outside the viewport
- provided selector is empty
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/c7a0e951ee1a2aab.
Report an issue: GitHub.