Skip to main content
Glama

browser_add_init_script

Read-onlyIdempotent

Register JavaScript that runs BEFORE the page's own code, at document start, on every page opened afterwards in this identity's context. Use when browser.evaluate is too late — most often to hook window.fetch/XMLHttpRequest and capture a SPA's request bodies, which network_requests cannot show. Does NOT affect already-open pages: add the script first, then browser.open. Cannot be removed once added; it lives until the context is evicted or browser.close is called.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYes
in_workspaceNoRun this one call in this workspace id instead of the session's. Nothing is stored; other sessions are not affected.
identity_nameNo_anon

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / properties / in_workspace
      Added value: +{
      +  "description": "Run this one call in this workspace id instead of the session's. Nothing is stored; other sessions are not affected.",
      +  "type": "integer"
      +}
  2. Added

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already declare the safety profile (readOnlyHint=true, destructiveHint=false, idempotentHint=true), yet the description goes well beyond them: injection timing relative to page code, forward-only scope, and the fact that registration is irreversible and lives until context eviction or browser.close. That lifetime/irreversibility detail is exactly the kind of context the structured fields cannot convey.

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

Conciseness5/5

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

Four sentences, front-loaded with the action and timing, then the routing rule, then the two constraints (non-retroactive, non-removable). No filler or repetition.

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 1-required-param action tool with no output schema, the behavioral surface is well covered: timing, scope, irreversibility, and alternatives. The only shortfall is that no parameter-level semantics (script format, identity_name default) are supplied to offset the thin schema descriptions.

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 description coverage is only 33% (only in_workspace is documented), so the description is expected to compensate. It implies the meaning of the "script" argument (document-start JS) and the identity scoping via "this identity's context," but never names or explains the parameters, and says nothing about duplicate/`_anon` default behavior.

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 precise verb and resource ("Register JavaScript") plus its exact execution point ("runs BEFORE the page's own code, at document start") and scope ("every page opened afterwards in this identity's context"). It distinguishes itself from browser_evaluate and browser_network_requests by name, so an agent can route without opening any 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?

Gives an explicit when-to-use with a named alternative and the failure mode that selects it: "Use when browser.evaluate is too late... which network_requests cannot show." It also gives an ordering rule ("add the script first, then browser.open") and an exclusion ("Does NOT affect already-open pages").

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.