Skip to main content
Glama
Browser Session MCP

Browser Session MCP

add_init_script

Inject JavaScript into every tab at the start of each page load, before page scripts run, to record timings/DOM changes or stub APIs early; returns an ID for removal.

Instructions

Run JavaScript at the start of every page load in every tab of the session, before any of the page's own scripts, until removed or the session closes. Use it to record timings or DOM changes from the very first moment of a load (a MutationObserver, PerformanceObserver or console hook writing to a window global you read later with evaluate), or to stub an API before the page uses it. Takes effect from each tab's next navigation, not the page already loaded. It runs in the page's main world, so the page can see what it defines. Returns an id for remove_init_script. Needs the listener role.

Input Schema

NameRequiredDescriptionDefault
sourceYesThe JavaScript to run, as a script body (not a function).
sessionIdYesThe id returned by open_browser_session. Errors if no open session has it.

Output Schema

NameRequiredDescriptionDefault
idYesPass to remove_init_script.
networkNoNetwork throttling; null means none.
initScriptsYes
cpuThrottlingRateYesCPU slowdown factor; 1 means none.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.1.18

TDQS

A4.5/5.0
Behavior5/5

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

Annotations only declare the mutation profile (readOnlyHint=false, idempotentHint=false, destructiveHint=false); the description adds the facts an agent actually needs: the script persists across navigations until removed or the session closes, it takes effect only from the next navigation rather than the already-loaded page, it executes in the page's main world so the page can observe what it defines, and the listener role is required.

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?

Front-loaded with the core behavior, then timing caveat, then use cases, then execution context and prerequisites. Every sentence carries distinct information; there is no restatement of the tool name or filler.

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

Completeness5/5

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

For a persistent, cross-tab injection tool this covers scope, lifecycle, activation timing, execution world, auth requirement and the follow-up id. An output schema exists, so return values need no explanation, and nothing an agent needs in order to call this correctly is missing.

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 100% and both parameters are documented in the schema, including that 'source' is a script body rather than a function. The description adds no further parameter-level detail beyond noting the returned id feeds remove_init_script, so the schema is doing the heavy lifting and the baseline 3 applies.

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?

The opening sentence names a specific verb and resource ('Run JavaScript at the start of every page load') and pins down scope: every tab in the session, before the page's own scripts, until removed or the session closes. That is distinguishable at a glance from siblings like evaluate, which reads values in an already-loaded page.

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

Usage Guidelines4/5

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

It gives concrete when-to-use cases (recording timings/DOM changes via MutationObserver, PerformanceObserver or console hooks; stubbing an API before first use) and points to evaluate for reading the resulting window global and to remove_init_script for teardown. It stops short of an explicit 'do not use this for X' exclusion, so 4 rather than 5.

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