browserless_function
Execute custom Puppeteer scripts to automate browser tasks like scraping and form filling. Control response type by returning data and content-type.
Instructions
Execute custom Puppeteer JavaScript code on the Browserless cloud. Your function receives a Puppeteer page object and optional context data. Return { data, type } to control the response payload and Content-Type.
For binary outputs, set type to a real MIME so the bytes come back as a proper content block instead of base64 text:
image/png/image/jpeg/image/webp→ vision content block (~1.5K tokens)audio/mpeg/audio/wav→ audio content blockapplication/pdfand other binaries → resource content block (attachment)
Text responses are capped at 200,000 characters (~50K tokens). Larger text payloads will be rejected — filter or summarize inside your function, or switch to a binary type if you actually meant to return bytes.
Useful for complex scraping, form filling, or any browser automation that requires custom code.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | 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. | |
| _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 first. | |
| timeout | No | Request timeout in milliseconds |