{"record":{"id":"490ca99de703af5b","repo":"grafana/k6","slug":"parsing-page-dispatch-event-options-w","errorCode":null,"errorMessage":"parsing page dispatch event options: %w","messagePattern":"parsing page dispatch event options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":84,"sourceCode":"\t\t\t\treturn p.Content() //nolint:wrapcheck\n\t\t\t})\n\t\t},\n\t\t\"context\": func() mapping {\n\t\t\treturn mapBrowserContext(vu, p.Context())\n\t\t},\n\t\t\"dblclick\": func(selector string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameDblclickOptions(rt, opts, p.MainFrame().Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing double click options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, p.Dblclick(selector, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"dispatchEvent\": func(selector, typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parseFrameDispatchEventOptions(rt, opts, p.MainFrame().Timeout())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing page dispatch event options: %w\", err)\n\t\t\t}\n\t\t\tearg := exportArg(eventInit)\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, p.DispatchEvent(selector, typ, earg, popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"emulateMedia\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts, err := parsePageEmulateMediaOptions(rt, opts, common.NewPageEmulateMediaOptions(p))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing emulateMedia options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, p.EmulateMedia(popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"emulateVisionDeficiency\": func(typ string) *sobek.Promise {\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, p.EmulateVisionDeficiency(typ) //nolint:wrapcheck","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/page_mapping.go#L66-L102","documentation":"Thrown synchronously by page.dispatchEvent(selector, type, eventInit, opts) when FrameDispatchEventOptions.Parse fails. In the current codebase this wrapper is defensive only: FrameDispatchEventOptions embeds FrameBaseOptions, whose Parse (internal/js/modules/k6/browser/common/frame_options.go:218-232) accepts only 'strict' (ToBoolean) and 'timeout' (ToInteger) and unconditionally returns nil. Unknown option keys are silently ignored and bad values are coerced, so the error cannot fire on this k6 version.","triggerScenarios":"No current input reaches this error; it exists to wrap future validation of strict/timeout. If you see it, you are likely on a fork or a different k6 version where FrameBaseOptions.Parse validates types (e.g. timeout as a non-numeric, non-coercible value).","commonSituations":"Running scripts against a custom xk6 build or a patched browser module that added strict timeout validation; upgrading k6 versions where the shared FrameBaseOptions parser gained error paths.","solutions":["Keep opts to the documented keys — only timeout (milliseconds) and strict (boolean) are read for dispatchEvent","If hit on a custom build, check that FrameBaseOptions.Parse in your tree matches upstream expectations and pass plain types","Pass no options at all when defaults suffice: page.dispatchEvent(sel, 'click', { ... })"],"exampleFix":"// before\nawait page.dispatchEvent('#el', 'custom', {}, { timeout: '30s' });\n\n// after\nawait page.dispatchEvent('#el', 'custom', {}, { timeout: 30000 });","handlingStrategy":"validation","validationCode":"const ALLOWED = new Set(['timeout', 'strict']);\nconst bad = Object.keys(opts ?? {}).filter(k => !ALLOWED.has(k));\nif (bad.length) console.warn(`dispatchEvent ignores unknown options: ${bad.join(', ')}`);\nif (opts?.timeout !== undefined && !Number.isInteger(opts.timeout)) {\n  throw new Error('dispatchEvent timeout must be integer milliseconds');\n}\nawait page.dispatchEvent(selector, type, eventInit, opts);","typeGuard":"/** @param {unknown} o */\nfunction isDispatchOpts(o) {\n  if (o === undefined || o === null) return true;\n  if (typeof o !== 'object') return false;\n  const t = /** @type {any} */ (o).timeout;\n  const s = /** @type {any} */ (o).strict;\n  return (t === undefined || Number.isInteger(t)) && (s === undefined || typeof s === 'boolean');\n}","tryCatchPattern":"try {\n  await page.dispatchEvent(selector, type, eventInit, opts);\n} catch (e) {\n  if (String(e).includes('parsing page dispatch event options')) {\n    await page.dispatchEvent(selector, type, eventInit); // retry with defaults\n  } else throw e;\n}","preventionTips":["dispatchEvent only reads timeout and strict — other keys are ignored","Pass timeout in milliseconds, never as '30s' strings","On custom builds, confirm which keys the local parser validates"],"tags":["k6","browser","page","dispatch-event","options"],"backgroundTag":"invalid-option-type","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-09-14T20:10:14.619Z","contentChangedAt":"2026-09-14T20:10:14.619Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}