browserless_function
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" })orreturn 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
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | 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. | |
| toDisk | No | 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. | |
| _prompt | No | The 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. | |
| context | No | Optional context object passed to the function as the second argument. | |
| profile | No | 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). | |
| timeout | No | Request timeout in milliseconds |