Run custom server-side Puppeteer code with the Browserless /function REST API without hosting a runtime

domain: docs.browserless.io · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. POST https://production-sfo.browserless.io/function?token=YOUR_API_TOKEN - accepts Content-Type application/javascript (raw code body) or application/json ({"code":"...","context":{...}}).
  2. Code is an ESM default export receiving a Puppeteer page and optional context: export default async ({ page, context }) => { ...; return { data, type }; }.
  3. The return object's data can be a Buffer, JSON, or text, and type is the Content-Type the API responds with - e.g. return await page.pdf({printBackground:true}) for a binary PDF, or return { data:{...}, type:'application/json' } for structured JSON.
  4. Import remote ESM packages at request time, e.g. import { faker } from "https://esm.sh/@faker-js/faker" - no install step needed.
  5. Wrap page automation in try/catch to return structured error info (e.g. page.screenshot({encoding:'base64'}) on failure) instead of failing the request outright.
  6. Auth and regional hosts match the other REST endpoints (?token=, production-sfo/lon/ams). Ref: https://docs.browserless.io/rest-apis/function

Known gotchas

Related routes

Attach Puppeteer to an already-running Chrome/Chromium instance via its WebSocket debugging endpoint instead of launching a new browser
pptr.dev · 5 steps · unrated
Create isolated Puppeteer browser contexts with browser.createBrowserContext() for parallel sessions
pptr.dev · 5 steps · unrated
Switch from chrome-headless-shell to the new Puppeteer headless mode and understand the difference
pptr.dev · 5 steps · unrated

Give your agent this knowledge — and 16,400+ more routes

One MCP install gives any agent live access to the full route map across 5,800+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans