{"record":{"id":"a177973ace905741","repo":"grafana/k6","slug":"parsing-element-handle-click-option-modifiers-w-mapping","errorCode":null,"errorMessage":"parsing element handle click option modifiers: %w","messagePattern":"parsing element handle click option modifiers: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/element_handle_mapping.go","lineNumber":609,"sourceCode":"\n\terr := parseElementHandleBasePointerOptions(&ehcopts.ElementHandleBasePointerOptions, rt, opts)\n\tif err != nil {\n\t\treturn ehcopts, err\n\t}\n\n\tobj := opts.ToObject(rt)\n\tfor _, k := range obj.Keys() {\n\t\tswitch k {\n\t\tcase \"button\":\n\t\t\tehcopts.Button = obj.Get(k).String()\n\t\tcase \"clickCount\":\n\t\t\tehcopts.ClickCount = obj.Get(k).ToInteger()\n\t\tcase \"delay\":\n\t\t\tehcopts.Delay = obj.Get(k).ToInteger()\n\t\tcase \"modifiers\":\n\t\t\tvar m []string\n\t\t\tif err := rt.ExportTo(obj.Get(k), &m); err != nil {\n\t\t\t\treturn ehcopts, fmt.Errorf(\"parsing element handle click option modifiers: %w\", err)\n\t\t\t}\n\t\t\tehcopts.Modifiers = m\n\t\t}\n\t}\n\treturn ehcopts, nil\n}\n\n// parseElementHandleBasePointerOptions parses the element handle base pointer options from a\n// Sobek value into o.\nfunc parseElementHandleBasePointerOptions(\n\to *common.ElementHandleBasePointerOptions, rt *sobek.Runtime, opts sobek.Value,\n) error {\n\tif k6common.IsNullish(opts) {\n\t\treturn nil\n\t}\n\n\tif err := parseElementHandleBaseOptions(&o.ElementHandleBaseOptions, rt, opts); err != nil {\n\t\treturn err","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/element_handle_mapping.go#L591-L627","documentation":"k6 browser's parseElementHandleClickOptions converts the JavaScript `modifiers` click option into a Go []string via rt.ExportTo. ExportTo fails when the Sobek value is not exportable as a string array (e.g. a string, number, or object), so k6 wraps the failure as 'parsing element handle click option modifiers'. Modifiers must be an array of key names such as 'Alt', 'Control', 'Meta', or 'Shift'.","triggerScenarios":"Calling page.click or elementHandle.click with options where `modifiers` is not an array of strings: e.g. modifiers: 'Shift' (bare string), modifiers: 5, modifiers: {0:'Shift'} as a non-array object, or an array containing non-string elements that Sobek cannot export to []string.","commonSituations":"Copy-pasting Playwright snippets that pass a single modifier string instead of an array; building the modifiers array dynamically and accidentally producing a non-array; typos that assign another option's value to modifiers; template literals producing a string instead of an array.","solutions":["Pass modifiers as an array of strings, e.g. { modifiers: ['Shift'] }","Verify the value type with Array.isArray(opts.modifiers) before calling click","Check each element is a string (filter with typeof m === 'string')","Remove the modifiers option entirely if not needed (it is optional)"],"exampleFix":"// before\nawait page.click('#submit', { modifiers: 'Shift' });\n\n// after\nawait page.click('#submit', { modifiers: ['Shift'] });","handlingStrategy":"validation","validationCode":"const MODIFIERS = ['Alt', 'Control', 'Meta', 'Shift'];\nfunction validModifiers(opts) {\n  return opts == null || opts.modifiers === undefined ||\n    (Array.isArray(opts.modifiers) && opts.modifiers.every(m => typeof m === 'string' && MODIFIERS.includes(m)));\n}","typeGuard":"function isStringArray(v) {\n  return Array.isArray(v) && v.every(x => typeof x === 'string');\n}","tryCatchPattern":"try {\n  await page.click(sel, { modifiers: ['Shift'] });\n} catch (e) {\n  if (String(e).includes('parsing element handle click option modifiers')) {\n    throw new Error('modifiers must be an array of strings, e.g. [\\'Shift\\']: ' + e);\n  }\n  throw e;\n}","preventionTips":["Always wrap single modifiers in an array: ['Shift'], never 'Shift'","Only use the supported modifier names: Alt, Control, Meta, Shift","Unit-test option objects before passing them to click","Validate option shapes with a helper before invoking browser APIs"],"tags":["browser","javascript","click-options","type-mismatch"],"backgroundTag":"invalid-argument-format","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-09-14T20:10:14.619Z","contentChangedAt":"2026-09-14T20:10:14.619Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}