Skip to main content
Glama
CodeInKlingon

@codeinklingon/browser-mcp

browser_tab_run

Run JavaScript code in an open browser tab to automate page interactions and data extraction. Requires tab to be opened first.

Instructions

Execute JavaScript code in the browser tab. The code runs as an async function body.

CRITICAL RULES:

  • MUST call browser_tab_open before browser_tab_run

  • ALWAYS await async tab methods

  • tab.observe() and tab.goto() invalidate previous element refs

  • Default to tab.observe() for page state; screenshot only when appearance matters

  • For reading static content (articles, docs, JSON, PDFs), prefer webfetch — browser is for JS execution, auth, interactive actions

Available variables in scope:

  • tab — TabApi object: tab.url(): string (sync) tab.title(): Promise tab.goto(url, { waitUntil? }) waitUntil: 'load' | 'domcontentloaded' | 'networkidle' tab.click(selector) CSS, "text/...", "xpath/...", "aria-ref=..." tab.type(selector, text) tab.fill(selector, value) clear + type into input tab.press(key, { selector? }) e.g. 'Enter', 'Escape' tab.hover(selector) tab.scroll(deltaX, deltaY) tab.scrollIntoView(selector) tab.screenshot({ fullPage?, selector? }) returns base64 PNG tab.evaluate(fn, ...args) raw JS in page context tab.observe() accessibility tree: { elements: [{ id, role, name, value, focused }] } tab.ariaSnapshot() Playwright-format YAML tree with [ref=eN] ids, [cursor=pointer] for clickables tab.id(n) ElementHandleActions from observe() id tab.ref("e5") ElementHandleActions from ariaSnapshot() ref tab.waitForSelector(selector, { timeout?, visible?, hidden? }) tab.waitForUrl(pattern, { timeout? }) string substring or RegExp tab.waitForResponse(pattern, { timeout? }) string, RegExp, or (res) => boolean tab.waitForNavigation({ waitUntil?, timeout? }) tab.select(selector, ...values) option(s) tab.drag(from, to) selector or { x, y } point tab.extract(format?) 'markdown' | 'text' | omitted (returns HTML) tab.uploadFile(selector, ...filePaths) file input

ElementHandleActions: { click, type, fill, hover, focus, screenshot, evaluate, scrollIntoView }

  • display(value) — emit structured output (NOT a tab.* method)

  • wait(ms) — delay (NOT a tab.* method; use bare wait(2000), not tab.wait(...))

  • assert(cond, msg?) — guard (NOT a tab.* method)

Selectors: CSS by default, "text/Sign in" for visible text, "xpath/...", "aria-ref=e5" from ariaSnapshot.

Single-expression code auto-returns its value (no explicit 'return' needed). Use display() for intermediate values.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesJavaScript code body to execute
Behavior5/5

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

With no annotations, the description fully bears the burden of behavioral disclosure. It details the async execution context, available methods, and important behaviors like invalidated element refs. No contradictions exist.

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?

The description is long but well-structured with critical rules upfront and organized sections. Every sentence adds value for a powerful tool, though some details could be condensed.

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?

Given the tool's complexity with many methods and no output schema, the description thoroughly explains all necessary context, including scope variables and usage patterns like single-expression auto-return.

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?

The single parameter 'code' is fully described in the schema (100% coverage). The description adds useful context about auto-return and single-expression behavior, exceeding the schema's simple description.

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 description clearly states 'Execute JavaScript code in the browser tab' with a specific verb and resource. It distinguishes from sibling tools (browser_tab_close, browser_tab_open) by focusing on code execution.

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 description provides explicit prerequisites (must call browser_tab_open first) and alternatives (prefer webfetch for static content), guiding the agent on when to use this tool.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CodeInKlingon/browser-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server