{"record":{"id":"79d5db31895afe94","repo":"GopeedLab/gopeed","slug":"execute-expects-a-string-or-function-79d5db","errorCode":null,"errorMessage":"execute expects a string or function","messagePattern":"execute expects a string or function","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/download/extension_runtime_webview.go","lineNumber":146,"sourceCode":"\t\treturn goja.Undefined()\n\t})\n\t_ = obj.Set(\"goto\", func(call goja.FunctionCall) goja.Value {\n\t\turl, err := requireStringArg(call, 0, \"url\")\n\t\tif err != nil {\n\t\t\tpanic(vm.ToValue(err))\n\t\t}\n\t\tif err := page.Goto(\n\t\t\turl,\n\t\t\toptionalMap(call.Argument(1)),\n\t\t); err != nil {\n\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 {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/GopeedLab/gopeed/blob/7b7327ffb30816273a74b142cccc0bc10c5a4c67/pkg/download/extension_runtime_webview.go#L128-L164","documentation":"Raised by the execute binding (extension_runtime_webview.go:143-147) when NormalizeExecutableValue receives no value at all: its first branch returns this error for a nil argument (pkg/download/engine/webview/runtime.go:572-575). It means page.execute() was invoked without any expression, so there is nothing to serialize and hand to the webview's page.Execute.","triggerScenarios":"Calling page.execute() with zero arguments; spreading an empty args array (page.execute(...fns) with fns = []); calling through a wrapper that conditionally drops its argument.","commonSituations":"Generic helper wrappers like run(step) that forward step.expr which can be undefined; code migrated from an API where execute() was a no-op without arguments; conditional expressions evaluating to undefined.","solutions":["Always pass a first argument: a JS expression string or a function","Validate the dynamic expression before calling execute","Prefer a function so arguments can be forwarded: page.execute((a) => a.title, page)"],"exampleFix":"// before\npage.execute();\n\n// after\nconst title = page.execute(\"document.title\");","handlingStrategy":"validation","validationCode":"if (expr === undefined || expr === null) {\n  throw new TypeError(\"execute requires an expression or function\");\n}\npage.execute(expr);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a first argument to execute()","In wrapper helpers, default to a harmless expression: page.execute(expr ?? \"undefined\")","Log the intended expression before executing during development"],"tags":["extension","webview","execute","validation"],"backgroundTag":null,"analyzedSha":"7b7327ffb30816273a74b142cccc0bc10c5a4c67","analyzedAt":"2026-08-16T02:51:03.250Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}