Skip to main content
Glama

browser_evaluate

Evaluates JavaScript in an attached Chrome or Edge tab to extract data or return DOM element references, with optional wait checks and cursor-based cached reads.

Instructions

Evaluate once without user activation; call a returned function once and await its Promise. Completed JSON can be historical (source_current=false) after source change, without a continuation; element refs remain strict. cursor reads cache without execution. Return large collections as a top-level array of small records, not a nested array wrapper; required_chars/next_item guide cursor budgets, capture_truncated is unrecoverable source loss.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "tab_handle": "<tab_handle>"
    },
    "name": "browser_evaluate"
  }
}

Input Schema

NameRequiredDescriptionDefault
frameNoChild frame; see shared locator rules.
cursorNoExactly one of expression/cursor. Cursor reads cached JSON; omit frame/frame_id and result_type=element.
frame_idNo
wait_forNoPost-action checks (same conditions as wait); shares the total action budget. Result is wait_result, never input replay.
max_charsNoPer-page JSON value budget, excluding metadata; capture cap 1M chars / 50000 nodes / depth 8.
expressionNo
tab_handleYes
timeout_msNo
result_typeNoelement: return one connected DOM element as a ref.json
dialog_policyNoask

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changedv0.34.0
    • removedInput schema / properties / dialog_policy / description
      Removed value: -"accept/dismiss auto-handle dialogs and return their messages."
    • changedInput schema / properties / frame / description
      Previous value: -"Child frame: at least one of url/title/path. url/title exact; path=unique nested CSS iframe steps (e.g. [\"#frame\"]); exclusive with frame_id."New value: +"Child frame; see shared locator rules."
    • addedInput schema / properties / wait_for
      Added value: +{
      +  "additionalProperties": false,
      +  "description": "Post-action checks (same conditions as wait); shares the total action budget. Result is wait_result, never input replay.",
      +  "properties": {
      +    "checks": {
      +      "items": {
      +        "additionalProperties": false,
      +        "properties": {
      +          "condition": {
      +            "enum": [
      +              "attached",
      +              "absent",
      +              "visible",
      +              "actionable",
      +              "text",
      +              "value",
      +              "checked",
      +              "selected",
      +              "expanded",
      +              "url",
      +              "network_idle",
      +              "count",
      +              "value_present"
      +            ],
      +            "type": "string"
      +          },
      +          "expected": {
      +            "anyOf": [
      +              {
      +                "maxLength": 100000,
      +                "type": "string"
      +              },
      +              {
      +                "type": "boolean"
      +              },
      +              {
      +                "maximum": 9007199254740991,
      +                "minimum": 0,
      +                "type": "integer"
      +              }
      +            ],
      +            "description": "text/url: substring; value: exact; count: integer; states: boolean (checked also mixed)."
      +          },
      +          "frame": {
      +            "additionalProperties": false,
      +            "properties": {
      +              "path": {
      +                "items": {
      +                  "minLength": 1,
      +                  "type": "string"
      +                },
      +                "maxItems": 16,
      +                "minItems": 1,
      +                "type": "array"
      +              },
      +              "title": {
      +                "minLength": 1,
      +                "type": "string"
      +              },
      +              "url": {
      +                "minLength": 1,
      +                "type": "string"
      +              }
      +            },
      +            "type": "object"
      +          },
      +          "frame_id": {
      +            "type": "string"
      +          },
      +          "idle_ms": {
      +            "maximum": 10000,
      +            "minimum": 100,
      +            "type": "integer"
      +          },
      +          "name": {
      +            "maxLength": 10000,
      +            "type": "string"
      +          },
      +          "not": {
      +            "type": "boolean"
      +          },
      +          "nth": {
      +            "maximum": 9007199254740991,
      +            "minimum": 0,
      +            "type": "integer"
      +          },
      +          "previous": {
      +            "description": "text: full prior innerText; exclusive with expected.",
      +            "maxLength": 100000,
      +            "type": "string"
      +          },
      +          "selector": {
      +            "maxLength": 10000,
      +            "minLength": 1,
      +            "type": "string"
      +          },
      +          "selector_type": {
      +            "enum": [
      +              "css",
      +              "xpath",
      +              "label",
      +              "placeholder",
      +              "role"
      +            ],
      +            "type": "string"
      +          }
      +        },
      +        "required": [
      +          "condition"
      +        ],
      +        "type": "object"
      +      },
      +      "maxItems": 30,
      +      "minItems": 1,
      +      "type": "array"
      +    },
      +    "timeout_ms": {
      +      "default": 5000,
      +      "maximum": 30000,
      +      "minimum": 100,
      +      "type": "integer"
      +    }
      +  },
      +  "required": [
      +    "checks"
      +  ],
      +  "type": "object"
      +}
  2. Changed4 schema fields changedv0.24.2
    • changedInput schema / properties / cursor / description
      Previous value: -"Cached JSON instead of expression; omit frame, frame_id and result_type=element."New value: +"Exactly one of expression/cursor. Cursor reads cached JSON; omit frame/frame_id and result_type=element."
    • changedInput schema / properties / dialog_policy / description
      Previous value: -"accept/dismiss returns handled dialog messages."New value: +"accept/dismiss auto-handle dialogs and return their messages."
    • changedInput schema / properties / frame / description
      Previous value: -"Exact child-frame URL/title or CSS iframe path (e.g. [\"#content_iframe\"]); alternative to frame_id. Each path entry uniquely selects an iframe in the preceding document."New value: +"Child frame: at least one of url/title/path. url/title exact; path=unique nested CSS iframe steps (e.g. [\"#frame\"]); exclusive with frame_id."
    • addedInput schema / properties / result_type / description
      Added value: +"element: return one connected DOM element as a ref."
  3. First observedv0.24.0

TDQS

B3.2/5.0
Behavior4/5

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

With no annotations, the description carries real behavioral load: single execution without user activation, calling a returned function once and awaiting its Promise, stale/historical JSON after source change (source_current=false) with no continuation, strict element refs, cache-only cursor reads, and unrecoverable capture_truncated loss. These are non-obvious traits an agent could not get from the schema; only the total action budget/timeout behavior is left unstated.

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

Conciseness3/5

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

The first clause is front-loaded and useful, but the run-on sentences compress several distinct behaviors into telegraphic fragments, forcing re-parsing. Every clause does carry information, but the lack of structure (no separation of execution vs. cursor vs. output shaping) hurts readability.

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

Completeness3/5

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

For a 10-parameter, nested-schema tool with no output schema and no annotations, the description covers execution semantics and result shaping but is silent on the wait_for post-action checks, dialog handling, and frame targeting. Important call-correctness details remain solely in the schema, leaving the definition adequate but incomplete.

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

Parameters3/5

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

Schema coverage is 50% across 10 params. The description clarifies cursor semantics (omit frame/frame_id and result_type=element), the element result type, and adds returned-metadata vocabulary (required_chars, next_item, capture_truncated, source_current). It says nothing meaningful about wait_for, dialog_policy, timeout_ms, or frame, so it compensates only partially for the coverage gap.

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

Purpose3/5

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

The description says 'Evaluate once without user activation' and discusses returning JSON, cursors, and element refs, but never plainly states that it executes a JavaScript expression in a tab and returns a JSON value. The verb+resource are implied rather than stated, so an agent must infer the core purpose from the schema enum and param names.

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

Usage Guidelines3/5

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

'Evaluate once without user activation' and 'cursor reads cache without execution' imply when to pass expression versus cursor, and the 'Exactly one of expression/cursor' rule appears in the schema. However, there is no explicit routing to siblings (e.g. when to prefer browser_read_text, browser_snapshot, or browser_wait) and no statement of when not to use evaluation.

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