Skip to main content
Glama

browser_eval

Evaluate JavaScript, extract DOM HTML, or read SSR-injected SPA state to inspect and operate on browser tabs via CDP.

Instructions

Purpose: Inspect or operate on a browser tab via 3 actions: 'js' (evaluate JS), 'dom' (get HTML), 'appState' (extract SSR-injected SPA state). Details: action='js' — Run a JS expression. withPerception:true wraps in {ok, result, post}. action='dom' — Return outerHTML of selector (or document.body), truncated to maxLength. action='appState' — Scan Next/Nuxt/Remix/Apollo/GitHub/Redux SSR injected JSON; pass selectors to override defaults. Prefer: Use action='appState' BEFORE 'dom' or 'js' on SPAs where rendered HTML is sparse — single CDP call. Use 'dom' when 'appState' is empty and you need page structure. Use 'js' as the escape hatch for arbitrary scripting. Caveats: DOM nodes cannot be returned from action='js' directly (circular refs are serialized safely). React/Vue/Svelte controlled inputs cannot be set via element.value — use keyboard(action='type') / browser_fill instead. readyState is strictly checked; guard blocks if page is still loading. Typed errors: code:'BrowserNotConnected' on CDP disconnect (re-attach via browser_open); code:'AutoGuardBlocked' when the auto-guard refuses (e.g. page still loading) — the error message preserves the guard's 1-sentence recommended next step (most often wait_until({condition:'ready_state'}) or browser_eval readyState polling, then retry). Examples: browser_eval({action:'js', expression:'document.title'}) → page title browser_eval({action:'dom', selector:'#main', maxLength:5000}) → outerHTML browser_eval({action:'appState'}) → default SPA state probes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
portNoChrome/Edge CDP remote debugging port (default 9222; configurable via desktop-touch-config.json)
tabIdNoTab ID from browser_open. Omit to use the first page tab.
actionYesAction selector — one of: js, dom, appState. Per-action required fields are enforced at call time (see the tool description); this flat schema lists every action's fields as optional.
lensIdNoOptional perception lens ID. Guards (target.identityStable) are evaluated before eval.
includeNoOptional response-shape opt-in. `['envelope']` returns the self-documenting envelope (`_version` / `data` / `as_of` / `confidence`). `['raw']` forces raw shape (overrides DESKTOP_TOUCH_ENVELOPE=1 server default). Default behaviour is raw shape (compat with existing clients).
maxBytesNoMax bytes per individual payload (default 4000). Larger payloads are truncated.
selectorNoCSS selector for root element. Omit for document.body.
maxLengthNoMax characters of HTML to return (default 10000).
selectorsNoCustom probe selectors. Omit to use the default SPA framework set (__NEXT_DATA__ / __NUXT_DATA__ / __REMIX_CONTEXT__ / __APOLLO_STATE__ / window:__INITIAL_STATE__ etc.). Window globals must be prefixed with 'window:'.
expressionNoJavaScript expression to evaluate. The server automatically wraps snippets in an async IIFE to avoid repeated const/let collisions. For multi-statement snippets, use an explicit final return value. Declarations (const/let/var) are scoped per snippet — use window.* / globalThis.* for persistence. A single eval is bounded by the CDP per-command timeout (~15s): do NOT write in-page polling loops here — use wait_until (element_matches / url_matches / ready_state) to wait for conditions instead.
includeContextNoWhen true (default), append `activeTab` + `readyState` lines to the response. Set false to skip — saves ~150 tokens per call when chaining several browser_* calls in the same tab.
withPerceptionNoWhen true, return structured JSON {ok, result, post} with post.perception attached. Default false preserves raw-text return.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed5 schema fields changedv2.3.1
    • addedInput schema / $schema
      Added value: +"http://json-schema.org/draft-07/schema#"
    • removedInput schema / additionalProperties
      Removed value: -false
    • changedInput schema / properties / includeContext / description
      Previous value: -"When true, append activeTab and readyState context to the response."New value: +"When true (default), append `activeTab` + `readyState` lines to the response. Set false to skip — saves ~150 tokens per call when chaining several browser_* calls in the same tab."
    • changedInput schema / properties / port / description
      Previous value: -"Chrome/Edge CDP remote debugging port."New value: +"Chrome/Edge CDP remote debugging port (default 9222; configurable via desktop-touch-config.json)"
    • addedInput schema / properties / selectors / items
      Added value: +{
      +  "type": "string"
      +}
  2. Addedv1.12.0
  3. Removedv1.10.4
  4. Addedv1.9.2
  5. Removedv1.8.0
  6. Addedv1.6.0
  7. Removedv1.5.1
  8. Addedv1.5.0
  9. Removedv1.4.3
  10. Addedv1.4.2
  11. Removedv1.4.0
  12. Changed1 schema field changedv1.2.1
    • changedInput schema / oneOf
      Previous value: -[
      -  {
      -    "additionalProperties": false,
      -    "properties": {
      -      "action": {
      -        "const": "js"
      -      },
      -      "expression": {
      -        "description": "JavaScript expression to evaluate. The server automatically wraps snippets in an async IIFE to avoid repeated const/let collisions. For multi-statement snippets, use an explicit final return value. Declarations (const/let/var) are scoped per snippet — use window.* / globalThis.* for persistence.",
      -        "type": "string"
      -      },
      -      "includeContext": {
      -        "default": true,
      -        "description": "When true, append activeTab and readyState context to the response.",
      -        "type": "boolean"
      -      },
      -      "lensId": {
      -        "description": "Optional perception lens ID. Guards (target.identityStable) are evaluated before eval.",
      -        "type": "string"
      -      },
      -      "port": {
      -        "default": 9222,
      -        "description": "Chrome/Edge CDP remote debugging port.",
      -        "maximum": 65535,
      -        "minimum": 1,
      -        "type": "integer"
      -      },
      -      "tabId": {
      -        "description": "Tab ID from browser_open. Omit to use the first page tab.",
      -        "type": "string"
      -      },
      -      "withPerception": {
      -        "default": false,
      -        "description": "When true, return structured JSON {ok, result, post} with post.perception attached. Default false preserves raw-text return.",
      -        "type": "boolean"
      -      }
      -    },
      -    "required": [
      -      "action",
      -      "expression"
      -    ],
      -    "type": "object"
      -  },
      -  {
      -    "additionalProperties": false,
      -    "properties": {
      -      "action": {
      -        "const": "dom"
      -      },
      -      "includeContext": {
      -        "default": true,
      -        "description": "When true, append activeTab and readyState context to the response.",
      -        "type": "boolean"
      -      },
      -      "maxLength": {
      -        "default": 10000,
      -        "description": "Max characters of HTML to return (default 10000).",
      -        "maximum": 100000,
      -        "minimum": 100,
      -        "type": "integer"
      -      },
      -      "port": {
      -        "default": 9222,
      -        "description": "Chrome/Edge CDP remote debugging port.",
      -        "maximum": 65535,
      -        "minimum": 1,
      -        "type": "integer"
      -      },
      -      "selector": {
      -        "description": "CSS selector for root element. Omit for document.body.",
      -        "type": "string"
      -      },
      -      "tabId": {
      -        "description": "Tab ID from browser_open. Omit to use the first page tab.",
      -        "type": "string"
      -      }
      -    },
      -    "required": [
      -      "action"
      -    ],
      -    "type": "object"
      -  },
      -  {
      -    "additionalProperties": false,
      -    "properties": {
      -      "action": {
      -        "const": "appState"
      -      },
      -      "includeContext": {
      -        "default": true,
      -        "description": "When true, append activeTab and readyState context to the response.",
      -        "type": "boolean"
      -      },
      -      "maxBytes": {
      -        "default": 4000,
      -        "description": "Max bytes per individual payload (default 4000). Larger payloads are truncated.",
      -        "maximum": 64000,
      -        "minimum": 256,
      -        "type": "integer"
      -      },
      -      "port": {
      -        "default": 9222,
      -        "description": "Chrome/Edge CDP remote debugging port.",
      -        "maximum": 65535,
      -        "minimum": 1,
      -        "type": "integer"
      -      },
      -      "selectors": {
      -        "description": "Custom probe selectors. Omit to use the default SPA framework set (__NEXT_DATA__ / __NUXT_DATA__ / __REMIX_CONTEXT__ / __APOLLO_STATE__ / window:__INITIAL_STATE__ etc.). Window globals must be prefixed with 'window:'.",
      -        "type": "array"
      -      },
      -      "tabId": {
      -        "description": "Tab ID from browser_open. Omit to use the first page tab.",
      -        "type": "string"
      -      }
      -    },
      -    "required": [
      -      "action"
      -    ],
      -    "type": "object"
      -  }
      -]New value: +[
      +  {
      +    "additionalProperties": false,
      +    "properties": {
      +      "action": {
      +        "const": "js"
      +      },
      +      "expression": {
      +        "description": "JavaScript expression to evaluate. The server automatically wraps snippets in an async IIFE to avoid repeated const/let collisions. For multi-statement snippets, use an explicit final return value. Declarations (const/let/var) are scoped per snippet — use window.* / globalThis.* for persistence.",
      +        "type": "string"
      +      },
      +      "include": {
      +        "description": "Optional response-shape opt-in. `['envelope']` returns the self-documenting envelope (`_version` / `data` / `as_of` / `confidence`). `['raw']` forces raw shape (overrides DESKTOP_TOUCH_ENVELOPE=1 server default). Default behaviour is raw shape (compat with existing clients).",
      +        "items": {
      +          "type": "string"
      +        },
      +        "type": "array"
      +      },
      +      "includeContext": {
      +        "default": true,
      +        "description": "When true, append activeTab and readyState context to the response.",
      +        "type": "boolean"
      +      },
      +      "lensId": {
      +        "description": "Optional perception lens ID. Guards (target.identityStable) are evaluated before eval.",
      +        "type": "string"
      +      },
      +      "port": {
      +        "default": 9222,
      +        "description": "Chrome/Edge CDP remote debugging port.",
      +        "maximum": 65535,
      +        "minimum": 1,
      +        "type": "integer"
      +      },
      +      "tabId": {
      +        "description": "Tab ID from browser_open. Omit to use the first page tab.",
      +        "type": "string"
      +      },
      +      "withPerception": {
      +        "default": false,
      +        "description": "When true, return structured JSON {ok, result, post} with post.perception attached. Default false preserves raw-text return.",
      +        "type": "boolean"
      +      }
      +    },
      +    "required": [
      +      "action",
      +      "expression"
      +    ],
      +    "type": "object"
      +  },
      +  {
      +    "additionalProperties": false,
      +    "properties": {
      +      "action": {
      +        "const": "dom"
      +      },
      +      "include": {
      +        "description": "Optional response-shape opt-in. `['envelope']` returns the self-documenting envelope (`_version` / `data` / `as_of` / `confidence`). `['raw']` forces raw shape (overrides DESKTOP_TOUCH_ENVELOPE=1 server default). Default behaviour is raw shape (compat with existing clients).",
      +        "items": {
      +          "type": "string"
      +        },
      +        "type": "array"
      +      },
      +      "includeContext": {
      +        "default": true,
      +        "description": "When true, append activeTab and readyState context to the response.",
      +        "type": "boolean"
      +      },
      +      "maxLength": {
      +        "default": 10000,
      +        "description": "Max characters of HTML to return (default 10000).",
      +        "maximum": 100000,
      +        "minimum": 100,
      +        "type": "integer"
      +      },
      +      "port": {
      +        "default": 9222,
      +        "description": "Chrome/Edge CDP remote debugging port.",
      +        "maximum": 65535,
      +        "minimum": 1,
      +        "type": "integer"
      +      },
      +      "selector": {
      +        "description": "CSS selector for root element. Omit for document.body.",
      +        "type": "string"
      +      },
      +      "tabId": {
      +        "description": "Tab ID from browser_open. Omit to use the first page tab.",
      +        "type": "string"
      +      }
      +    },
      +    "required": [
      +      "action"
      +    ],
      +    "type": "object"
      +  },
      +  {
      +    "additionalProperties": false,
      +    "properties": {
      +      "action": {
      +        "const": "appState"
      +      },
      +      "include": {
      +        "description": "Optional response-shape opt-in. `['envelope']` returns the self-documenting envelope (`_version` / `data` / `as_of` / `confidence`). `['raw']` forces raw shape (overrides DESKTOP_TOUCH_ENVELOPE=1 server default). Default behaviour is raw shape (compat with existing clients).",
      +        "items": {
      +          "type": "string"
      +        },
      +        "type": "array"
      +      },
      +      "includeContext": {
      +        "default": true,
      +        "description": "When true, append activeTab and readyState context to the response.",
      +        "type": "boolean"
      +      },
      +      "maxBytes": {
      +        "default": 4000,
      +        "description": "Max bytes per individual payload (default 4000). Larger payloads are truncated.",
      +        "maximum": 64000,
      +        "minimum": 256,
      +        "type": "integer"
      +      },
      +      "port": {
      +        "default": 9222,
      +        "description": "Chrome/Edge CDP remote debugging port.",
      +        "maximum": 65535,
      +        "minimum": 1,
      +        "type": "integer"
      +      },
      +      "selectors": {
      +        "description": "Custom probe selectors. Omit to use the default SPA framework set (__NEXT_DATA__ / __NUXT_DATA__ / __REMIX_CONTEXT__ / __APOLLO_STATE__ / window:__INITIAL_STATE__ etc.). Window globals must be prefixed with 'window:'.",
      +        "type": "array"
      +      },
      +      "tabId": {
      +        "description": "Tab ID from browser_open. Omit to use the first page tab.",
      +        "type": "string"
      +      }
      +    },
      +    "required": [
      +      "action"
      +    ],
      +    "type": "object"
      +  }
      +]
  13. Addedv1.0.3
  14. Removedv0.15.7
  15. Changed1 schema field changedv0.13.1
    • addedInput schema / properties / withPerception
      Added value: +{
      +  "default": false,
      +  "description": "When true, return structured JSON { ok, result, post } instead of raw text. Enables post.perception attachment so the LLM can see guard status. Default false preserves the raw-text return for backwards compatibility. Example: browser_eval({expression:'document.title', withPerception:true})",
      +  "type": "boolean"
      +}
  16. Changed9 schema fields changedv0.10.0
    • removedInput schema / $schema
      Removed value: -"http://json-schema.org/draft-07/schema#"
    • addedInput schema / additionalProperties
      Added value: +false
    • removedInput schema / properties / _stub
      Removed value: -{
      -  "description": "Stub tool — arguments ignored."
      -}
    • addedInput schema / properties / expression
      Added value: +{
      +  "description": "JavaScript expression to evaluate in the browser tab",
      +  "type": "string"
      +}
    • addedInput schema / properties / includeContext
      Added value: +{
      +  "default": true,
      +  "description": "When true, append activeTab and readyState context to the response.",
      +  "type": "boolean"
      +}
    • addedInput schema / properties / lensId
      Added value: +{
      +  "description": "Optional perception lens ID. Guards (target.identityStable) are evaluated before eval. Note: browser_eval returns raw text, so no perception envelope is attached (guards only).",
      +  "type": "string"
      +}
    • addedInput schema / properties / port
      Added value: +{
      +  "default": 9222,
      +  "description": "Chrome/Edge CDP remote debugging port.",
      +  "maximum": 65535,
      +  "minimum": 1,
      +  "type": "integer"
      +}
    • addedInput schema / properties / tabId
      Added value: +{
      +  "description": "Tab ID from browser_connect. Omit to use the first page tab.",
      +  "type": "string"
      +}
    • addedInput schema / required
      Added value: +[
      +  "expression"
      +]
  17. First observedv0.6.2

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and discharges it: circular-ref serialization, controlled-input restrictions, strict readyState checking, and two typed errors (BrowserNotConnected, AutoGuardBlocked) with their recovery paths. It also notes the ~15s CDP eval bound and that polling loops belong in wait_until.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Labeled sections (Purpose / Details / Prefer / Caveats / Examples) are well front-loaded and skimmable. The Examples block re-states call shapes already implied by the schema, which is mild redundancy, but overall every section contributes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 12-parameter, no-annotation, no-output-schema tool this covers actions, error taxonomy, alternatives, and caveats thoroughly. The one gap is that return shapes per action are shown only by example rather than described, though withPerception and includeContext hints partially bridge it.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds real value: it ties parameters to actions (selector/maxLength belong to 'dom', selectors to 'appState'), explains withPerception's {ok, result, post} wrapping, and notes that per-action required fields are enforced at call time despite the flat schema. That last point is a genuine clarification of a schema quirk.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Inspect or operate on a browser tab') and immediately enumerates the three actions (js/dom/appState) with a one-line gloss of each. This distinguishes it from siblings like browser_navigate, browser_click, and browser_locate without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The 'Prefer' block gives explicit routing rules: appState before dom/js on SPAs, dom when appState is empty, js as the escape hatch, and keyboard/browser_fill instead of value-setting on controlled inputs. Alternatives and exclusions are stated, not implied.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.