GopeedLab/gopeed · error

execute expects a string or function

Error message

execute expects a string or function

What it means

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.

Source

Thrown at pkg/download/extension_runtime_webview.go:146

		return goja.Undefined()
	})
	_ = obj.Set("goto", func(call goja.FunctionCall) goja.Value {
		url, err := requireStringArg(call, 0, "url")
		if err != nil {
			panic(vm.ToValue(err))
		}
		if err := page.Goto(
			url,
			optionalMap(call.Argument(1)),
		); err != nil {
			panic(vm.ToValue(err))
		}
		return goja.Undefined()
	})
	_ = obj.Set("execute", func(call goja.FunctionCall) goja.Value {
		expression, err := enginewebview.NormalizeExecutableValue(call.Argument(0))
		if err != nil {
			panic(vm.ToValue(err))
		}
		result, err := page.Execute(expression, exportArgs(call.Arguments[1:])...)
		if err != nil {
			panic(vm.ToValue(err))
		}
		return vm.ToValue(result)
	})
	_ = obj.Set("focus", func(call goja.FunctionCall) goja.Value {
		selector, err := requireStringArg(call, 0, "selector")
		if err != nil {
			panic(vm.ToValue(err))
		}
		if err := page.Focus(selector); err != nil {
			panic(vm.ToValue(err))
		}
		return goja.Undefined()
	})
	_ = obj.Set("click", func(call goja.FunctionCall) goja.Value {

View on GitHub (pinned to 7b7327ffb3)

Solutions

  1. Always pass a first argument: a JS expression string or a function
  2. Validate the dynamic expression before calling execute
  3. Prefer a function so arguments can be forwarded: page.execute((a) => a.title, page)

Example fix

// before
page.execute();

// after
const title = page.execute("document.title");
Defensive patterns

Strategy: validation

Validate before calling

if (expr === undefined || expr === null) {
  throw new TypeError("execute requires an expression or function");
}
page.execute(expr);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of GopeedLab/gopeed@7b7327ffb3 (2026-08-16). Data as JSON: /api/errors/79d5db31895afe94. Report an issue: GitHub.