{"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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/locator_mapping.go","lineNumber":419,"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, err := parseFrameTapOptions(rt, opts, lo.DefaultTimeout())\n\t\t\tif 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, err := parseFrameDispatchEventOptions(rt, opts, lo.DefaultTimeout())\n\t\t\tif 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, err := parseFrameWaitForSelectorOptions(rt, opts, lo.Timeout())\n\t\t\tif 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":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/locator_mapping.go#L401-L437","documentation":"Thrown by k6 browser's Locator.dispatchEvent(type, eventInit, options) when the options argument cannot be parsed by FrameDispatchEventOptions (a FrameBaseOptions that only recognizes 'timeout' and 'strict'). Parsing happens synchronously in the Go mapping layer before any CDP command is sent, so a failure aborts the call immediately. The error wraps the underlying conversion failure from Sobek, k6's JavaScript runtime.","triggerScenarios":"Calling page.locator(...).dispatchEvent('click', {}, opts) with an opts value that Sobek cannot turn into an object (e.g. a BigInt like 100n or a Symbol), since null/undefined are allowed and plain numbers/strings get wrapped. Any error raised inside FrameBaseOptions.Parse (common/frame_options.go:218) while objectifying or reading keys also surfaces here.","commonSituations":"Porting Playwright scripts that pass option shapes k6's browser module does not accept; passing eventInit and options in swapped order so an unexpected value lands in the options slot; computed option variables that are undefined-but-not-null in edge cases.","solutions":["Pass an options object literal with only supported keys: locator.dispatchEvent('click', {bubbles: true}, {timeout: 5000, strict: false}).","Omit the third argument entirely (or pass null/undefined) to use the default timeout.","Check the variable you pass as options is a plain object (typeof opts === 'object') before the call.","If porting from Playwright, strip keys k6 does not parse (unknown keys are ignored anyway, but non-object values are not)."],"exampleFix":"// before\nlocator.dispatchEvent('click', {}, 5000);\n\n// after\nlocator.dispatchEvent('click', {}, { timeout: 5000 });","handlingStrategy":"validation","validationCode":"const ok = opts == null || (typeof opts === 'object' && !Array.isArray(opts));\nif (!ok) throw new Error('dispatchEvent options must be an object, null, or undefined');\nawait locator.dispatchEvent('click', eventInit, opts ?? { timeout: 5000 });","typeGuard":"function isDispatchEventOptions(v) {\n  if (v == null) return true;\n  if (typeof v !== 'object' || Array.isArray(v)) return false;\n  return Object.keys(v).every(k => (k === 'timeout' || k === 'strict'));\n}","tryCatchPattern":"try { await locator.dispatchEvent('click', init, opts); } catch (e) { if (/parsing locator dispatch event options/.test(e.message)) { /* fix opts and retry or fail fast */ } throw e; }","preventionTips":["Always pass an object literal (or nothing) as the third argument of locator.dispatchEvent.","Only set 'timeout' (integer ms) and 'strict' (boolean) keys in k6 dispatchEvent options.","Type option objects in TypeScript as { timeout?: number; strict?: boolean } to catch mistakes at compile time."],"tags":["k6","browser","locator","dispatch-event","options-parsing"],"backgroundTag":"invalid-options-argument","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"}