{"record":{"id":"a3d485e6d7792202","repo":"grafana/k6","slug":"parsing-locator-dispatch-event-options-w","errorCode":null,"errorMessage":"parsing locator dispatch event options: %w","messagePattern":"parsing locator dispatch event options: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/locator_mapping.go","lineNumber":418,"sourceCode":"\t\t\t\treturn nil, fmt.Errorf(\"parsing hover options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.Hover(copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"tap\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts := common.NewFrameTapOptions(lo.DefaultTimeout())\n\t\t\tif err := copts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing locator tap options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.Tap(copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"dispatchEvent\": func(typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewFrameDispatchEventOptions(lo.DefaultTimeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing locator dispatch event options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.DispatchEvent(typ, exportArg(eventInit), popts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t\t\"waitFor\": func(opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tcopts := common.NewFrameWaitForSelectorOptions(lo.Timeout())\n\t\t\tif err := copts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing wait for options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\treturn nil, lo.WaitFor(copts) //nolint:wrapcheck\n\t\t\t}), nil\n\t\t},\n\t}\n}\n\nfunc parseLocatorOptions(rt *sobek.Runtime, opts sobek.Value) *common.LocatorOptions {","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/locator_mapping.go#L400-L436","documentation":"Thrown when locator.dispatchEvent(type, eventInit, opts) fails to parse the third argument into FrameDispatchEventOptions (embeds FrameBaseOptions: strict, timeout number ms). The mapping wraps the cause as 'parsing locator dispatch event options: %w'. The eventInit payload is exported separately and is not part of this parse; only the trailing opts object is.","triggerScenarios":"dispatchEvent('click', { button: 0 }, '5s') — a scalar in the third (opts) slot; passing eventInit fields mixed into the options object; wrong-typed strict/timeout under strict parsers.","commonSituations":"Three-argument calls where the trailing duration string is easy to misplace; building synthetic events in tests and passing the payload as the last argument; ported Playwright snippets with different arity conventions.","solutions":["Keep three arguments in order: dispatchEvent('click', { button: 0 }, { timeout: 5000 })","Omit the third argument when defaults suffice","Keep only strict/timeout keys in the options object","Use numeric milliseconds for timeout"],"exampleFix":"// before\nawait page.locator('#el').dispatchEvent('click', { button: 0 }, '5s');\n\n// after\nawait page.locator('#el').dispatchEvent('click', { button: 0 }, { timeout: 5000 });","handlingStrategy":"validation","validationCode":"function assertDispatchEventOpts(opts) {\n  if (opts === null || opts === undefined) return;\n  if (typeof opts !== 'object' || Array.isArray(opts)) {\n    throw new TypeError('dispatchEvent options must be a plain object (third argument)');\n  }\n  if ('timeout' in opts && typeof opts.timeout !== 'number') {\n    throw new TypeError('dispatchEvent timeout must be a number (ms)');\n  }\n}","typeGuard":"function isLocatorBaseOptions(v) {\n  if (v === null || v === undefined) return true;\n  if (typeof v !== 'object' || Array.isArray(v)) return false;\n  return (v.timeout === undefined || typeof v.timeout === 'number') &&\n         (v.strict === undefined || typeof v.strict === 'boolean');\n}","tryCatchPattern":"try {\n  await locator.dispatchEvent('click', eventInit, opts);\n} catch (e) {\n  if (/parsing locator dispatch event options/.test(String(e.message))) {\n    throw new Error(`Bad dispatchEvent options (third argument): ${JSON.stringify(opts)}`);\n  }\n  throw e;\n}","preventionTips":["Keep the three slots distinct: event type, eventInit payload, options object","Put only strict/timeout in the options object","Use numeric milliseconds for timeout"],"tags":["k6","browser","locator","options","dispatchevent"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}