{"record":{"id":"76cb70397fa917eb","repo":"GopeedLab/gopeed","slug":"missing-or-invalid-selector","errorCode":null,"errorMessage":"missing or invalid \"selector\"","messagePattern":"missing or invalid \"selector\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/download/extension_runtime_webview.go","lineNumber":157,"sourceCode":"\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\treturn goja.Undefined()\n\t})\n\t_ = obj.Set(\"execute\", func(call goja.FunctionCall) goja.Value {\n\t\texpression, err := enginewebview.NormalizeExecutableValue(call.Argument(0))\n\t\tif err != nil {\n\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\tresult, err := page.Execute(expression, exportArgs(call.Arguments[1:])...)\n\t\tif err != nil {\n\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\treturn vm.ToValue(result)\n\t})\n\t_ = obj.Set(\"focus\", func(call goja.FunctionCall) goja.Value {\n\t\tselector, err := requireStringArg(call, 0, \"selector\")\n\t\tif err != nil {\n\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\tif err := page.Focus(selector); err != nil {\n\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\treturn goja.Undefined()\n\t})\n\t_ = obj.Set(\"click\", func(call goja.FunctionCall) goja.Value {\n\t\tselector, err := requireStringArg(call, 0, \"selector\")\n\t\tif err != nil {\n\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\tif err := page.Click(selector, optionalMap(call.Argument(1))); err != nil {\n\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\treturn goja.Undefined()\n\t})\n\t_ = obj.Set(\"type\", func(call goja.FunctionCall) goja.Value {\n\t\tselector, err := requireStringArg(call, 0, \"selector\")","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/GopeedLab/gopeed/blob/7b7327ffb30816273a74b142cccc0bc10c5a4c67/pkg/download/extension_runtime_webview.go#L139-L175","documentation":"Argument-presence error from requireStringArg raised by the focus binding (extension_runtime_webview.go:154-158): page.focus(selector) was called with a nil/undefined/null selector. The bridge validates presence before page.Focus runs, and any missing selector aborts the extension script with this exception.","triggerScenarios":"Calling page.focus() with no arguments; passing a selector variable that is undefined because a selector-lookup table had no entry; forwarding an optional parameter that the caller omitted.","commonSituations":"Site-specific selectors stored per-domain where one domain lacks an entry; refactors renaming the selector variable at the call site only; selector arrays iterated with a sparse index yielding undefined.","solutions":["Pass a concrete CSS selector: page.focus(\"#username\")","Guard dynamic selectors with a fallback or your own error before calling focus","Verify the selector table has an entry for the current site"],"exampleFix":"// before\nconst sel = selectors[host]; // undefined for unknown host\npage.focus(sel);\n\n// after\nconst sel = selectors[host];\nif (!sel) throw new Error(`no focus selector for host ${host}`);\npage.focus(sel);","handlingStrategy":"validation","validationCode":"if (!sel) throw new Error(\"focus selector is required\");\npage.focus(sel);","typeGuard":"function isSelector(v) {\n  return typeof v === \"string\" && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Keep per-site selector maps exhaustive and validate them at startup","Skip focus when the target is optional instead of calling with undefined","Reuse one shared selector-constant module across the extension"],"tags":["extension","webview","focus","selector","validation"],"backgroundTag":null,"analyzedSha":"7b7327ffb30816273a74b142cccc0bc10c5a4c67","analyzedAt":"2026-08-16T02:51:03.250Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}