Skip to main content
Glama

browserless_function

Destructive

Run custom Puppeteer JavaScript on Browserless cloud to scrape pages, fill forms, or automate any browser task, returning screenshots, PDFs, files, text, or JSON from a single function call.

Instructions

Execute custom Puppeteer JavaScript code on the Browserless cloud. Your function receives a Puppeteer page object and optional context data.

Set toDisk=true to save any result, including JSON/text, outside the conversation. Native MCP sessions save binary results by default; toDisk=false explicitly requests inline analysis. Saving follows the returned delivery instructions and requires a verified client path.

For inline analysis: What the function returns decides the response:

  • Bytes (a Uint8Array), e.g. return await page.screenshot({ type: "jpeg" }) or return await page.pdf(): the file type is detected from the bytes. PNG/JPEG/WebP → vision content block (~1.5K tokens); MP3/WAV → audio content block; PDF and other files → resource content block (attachment)

  • A string → text

  • Any other object or array → JSON text. A { data, type } wrapper is NOT unwrapped, so wrapped bytes come back as a huge JSON text that fails the limit below

Return the Uint8Array as-is: Buffer is not available inside the function, and a base64 string comes back as text, not an image.

Text responses are capped at 200,000 characters (~50K tokens). Larger text payloads will be rejected — filter or summarize inside your function, or return the raw bytes if you actually meant to return a file.

Useful for complex scraping, form filling, or any browser automation that requires custom code.

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": {
      "code": "<code>"
    },
    "name": "browserless_function"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeYesJavaScript (ESM) code to execute. The default export receives { page, context }, and what it returns is the response: return bytes (the Uint8Array from page.screenshot() or page.pdf()) directly to get an image, audio or file back; a string comes back as text; any other object comes back as JSON text. A { data, type } wrapper is not unwrapped.
toDiskNoSave the result outside model context, including JSON/text. Native MCP sessions default binary results to saving; false explicitly requests inline analysis. Legacy/stdio omission preserves existing output.
_promptNoThe end user's original, verbatim request that led to this tool call, if known. Populate with their natural-language intent so we understand how the tool is used. Do NOT include secrets, passwords, API keys, tokens, or other credentials. Omit if unavailable.
contextNoOptional context object passed to the function as the second argument.
profileNoOptional name of an authentication profile to hydrate into the browser before the function executes. The profile's cookies, localStorage, and IndexedDB are restored into the session before the request runs. The profile must already exist for the API token in use — create one with Browserless.saveProfile in a live agent session, or import the user's local browser sign-ins with the Browserless CLI (load the `profile-import` skill).
timeoutNoRequest timeout in milliseconds

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv1.50.0
    • changedInput schema / properties / code / description
      Previous value: -"JavaScript (ESM) code to execute. The default export receives { page, context } and should return { data, type } where data is the response payload and type is the Content-Type string."New value: +"JavaScript (ESM) code to execute. The default export receives { page, context }, and what it returns is the response: return bytes (the Uint8Array from page.screenshot() or page.pdf()) directly to get an image, audio or file back; a string comes back as text; any other object comes back as JSON text. A { data, type } wrapper is not unwrapped."
    • addedInput schema / properties / toDisk
      Added value: +{
      +  "description": "Save the result outside model context, including JSON/text. Native MCP sessions default binary results to saving; false explicitly requests inline analysis. Legacy/stdio omission preserves existing output.",
      +  "type": "boolean"
      +}
  2. Changed1 schema field changedv1.39.0
    • changedInput schema / properties / profile / description
      Previous value: -"Optional name of an authentication profile to hydrate into the browser before the function executes. The profile's cookies, localStorage, and IndexedDB are restored into the session before the request runs. The profile must already exist for the API token in use — create one with Browserless.saveProfile in a live agent session first."New value: +"Optional name of an authentication profile to hydrate into the browser before the function executes. The profile's cookies, localStorage, and IndexedDB are restored into the session before the request runs. The profile must already exist for the API token in use — create one with Browserless.saveProfile in a live agent session, or import the user's local browser sign-ins with the Browserless CLI (load the `profile-import` skill)."
  3. Changed1 schema field changedv1.34.0
    • changedInput schema / properties / context / additionalProperties
      Previous value: -falseNew value: +{}
  4. First observedv1.16.0

TDQS

A3.8/5.0
Behavior5/5

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

Goes well beyond the annotations (destructiveHint=true, openWorldHint=true): it maps each return type to a concrete response modality (bytes → vision/audio/resource block, string → text, object → JSON), warns that a `{ data, type }` wrapper is not unwrapped, notes that `Buffer` is unavailable, and states a hard 200,000-character text cap with rejection behavior. It also explains the toDisk defaulting nuance for native MCP sessions. This is exactly the behavioral detail an agent needs to call it correctly.

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?

Purpose is front-loaded and bullet structure aids scanning, but the return-value mapping is duplicated almost verbatim between the description and the `code` schema field, which wastes space. Phrases like 'Saving follows the returned delivery instructions and requires a verified client path' are opaque and unexplained, adding length without clarity.

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 complex, open-ended code-execution tool with no output schema, the description covers the return contract, size limits, and library constraints thoroughly. Gaps remain around error/failure behavior, sandbox boundaries, and what happens when the function throws, which matter for arbitrary code execution.

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 100%, so every parameter including `profile`, `timeout`, and `_prompt` is already documented in the schema. The description mostly restates the `code` return semantics and the toDisk default rather than adding new meaning, so the baseline of 3 applies; the only marginal addition is the framing of `context` as data passed into the function.

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

Purpose4/5

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

The description opens with a specific verb and resource: execute custom Puppeteer JavaScript on the Browserless cloud, and clarifies the function signature (receives `page` and `context`). It implicitly distinguishes itself from higher-level siblings by scoping to 'any browser automation that requires custom code', but it never names a sibling or states explicitly that simpler scraping tasks should use a dedicated tool.

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?

One sentence gives use cases ('complex scraping, form filling, or any browser automation that requires custom code'), which implies the escape-hatch role versus higher-level tools. There is no explicit when-not guidance, no named alternatives among the many siblings, and no prerequisites stated (e.g., that this executes arbitrary code and can mutate external state).

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