{"record":{"id":"c7a0e951ee1a2aab","repo":"grafana/k6","slug":"unknown-browser-event-q-must-be-q","errorCode":null,"errorMessage":"unknown browser event: %q, must be %q","messagePattern":"unknown browser event: %q, must be %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser.go","lineNumber":773,"sourceCode":"\n\tbrowserCtx, err := b.NewContext(opts)\n\tif err != nil {\n\t\treturn nil, spanRecordErrorf(span, \"new page: %w\", err)\n\t}\n\n\tpage, err := browserCtx.NewPage()\n\tif err != nil {\n\t\treturn nil, spanRecordError(span, err)\n\t}\n\n\treturn page, nil\n}\n\n// On returns a Promise that is resolved when the browser process is disconnected.\n// The only accepted event value is \"disconnected\".\nfunc (b *Browser) On(event string) (bool, error) {\n\tif event != EventBrowserDisconnected {\n\t\treturn false, fmt.Errorf(\"unknown browser event: %q, must be %q\", event, EventBrowserDisconnected)\n\t}\n\n\tselect {\n\tcase <-b.browserProc.lostConnection:\n\t\treturn true, nil\n\tcase <-b.vuCtx.Done():\n\t\treturn false, fmt.Errorf(\"browser.on promise rejected: %w\", ContextErr(b.vuCtx))\n\t}\n}\n\n// UserAgent returns the controlled browser's user agent string.\nfunc (b *Browser) UserAgent() string {\n\treturn b.version.userAgent\n}\n\n// Version returns the controlled browser's version.\nfunc (b *Browser) Version() string {\n\tproduct := b.version.product","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser.go#L755-L791","documentation":"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.","triggerScenarios":"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.","commonSituations":"Porting Playwright code that uses browser.on('disconnected') together with other event names; copy-paste from EventEmitter-style APIs; typos and case errors.","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"],"exampleFix":"// before\nawait browser.on('close') // throws: unknown browser event\n\n// after\nawait browser.on('disconnected')","handlingStrategy":"validation","validationCode":"const eventName = 'disconnected'\nif (eventName !== 'disconnected') {\n  throw new Error(`unsupported event: ${eventName}`)\n}\nawait browser.on(eventName)","typeGuard":"function isBrowserEvent(e) {\n  return e === 'disconnected'\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["api-misuse","events","browser","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}