DocsJavaScript Evaluationbrowser_evaluate

browser_evaluate

Browser Evaluate

Execute arbitrary JavaScript code in the page context. Has full access to the DOM, window object, and all page JavaScript. Use return_value=true to get the result of an expression.

Usage Example

1234567891011
import asyncio
from owl_browser import OwlBrowser, RemoteConfig
# Async usage
async with OwlBrowser(config) as browser:
context = await browser.create_context()
context_id = context["context_id"]
await browser.evaluate(
context_id=context_id
)

Parameters

Required

context_idstringrequired

The unique identifier of the browser context (e.g., 'ctx_000001')

Optional

scriptstring

JavaScript code to execute in the page context. Can access DOM, window object, etc. Example: 'document.title' or 'window.scrollY'. Optional if expression is provided.

expressionstring

JavaScript expression to evaluate and return (shorthand for script with return_value=true). If provided, script is optional and return_value is automatically true.

return_valueboolean

If true, treats the script as an expression and returns its value. If false (default), executes the script as statements. Automatically set to true when using expression.

Response

Returns a JSON object with the operation result.

{
  "success": true,
  "result": <value>
}