Stagehand icon

Stagehand

Control browser using Stagehand with AI automation

Evaluate

AI-generated

Summary

Execute arbitrary JavaScript code within the browser context managed by Stagehand, optionally passing JSON arguments into the function and returning the evaluation result along with current page URL.

Inputs

  • AI Provider — Selects the AI provider to use for any optionally integrated AI operations during the browser session. Defaults to 'OpenAI'.
  • JavaScript Code (required) — JavaScript code to execute in the browser context. This code runs as a function and should return a value representing the result of the evaluation.
  • Arguments (JSON) — JSON object containing arguments passed to the JavaScript function, accessible as function parameters during code execution. Defaults to an empty object.
  • Advanced Options — Collection of advanced settings such as specifying the AI model to use, caching, logging verbosity, timeouts for DOM settling and actions, resource blocking to speed page loads, and event wait conditions before code execution.

Output shape

a single JSON object containing the operation name, the evaluation result of the JavaScript code, the input arguments used, and the current page URL

If enabled, Stagehand log messages may also be included. Errors during code evaluation are returned as error objects tied to the operation. The operation requires an active browser session, initiating one automatically if needed. The JavaScript function executes in the context of the currently loaded page.

Discussion