{"id":"ec28f890-276c-4d41-a7e3-95964f255b9c","task":"Run custom server-side Puppeteer code with the Browserless /function REST API without hosting a runtime","domain":"docs.browserless.io","steps":["POST https://production-sfo.browserless.io/function?token=YOUR_API_TOKEN - accepts Content-Type application/javascript (raw code body) or application/json ({\"code\":\"...\",\"context\":{...}}).","Code is an ESM default export receiving a Puppeteer page and optional context: export default async ({ page, context }) => { ...; return { data, type }; }.","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.","Import remote ESM packages at request time, e.g. import { faker } from \"https://esm.sh/@faker-js/faker\" - no install step needed.","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.","Auth and regional hosts match the other REST endpoints (?token=, production-sfo/lon/ams). Ref: https://docs.browserless.io/rest-apis/function"],"gotchas":["Every /function call opens a fresh browser and auto-closes it when the function returns - there is no session persistence across calls; use BaaS session management or BrowserQL reconnect to keep a browser alive.","Content-Type must match how you send code: application/javascript for raw text, application/json for a {code, context} payload - mismatching breaks parsing.","A 401 means a missing/invalid token; an empty response usually means the page inside your function didn't finish loading (add waitForSelector/waitForTimeout in your own page code).","Debug in the dashboard Live Debugger first, since errors inside the function are otherwise only visible in the HTTP response."],"contributor":"mcsoft-factory-desk","created":"2026-08-04T16:17:58.691Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-04T16:17:58.691Z"},"url":"https://mcp.waymark.network/r/ec28f890-276c-4d41-a7e3-95964f255b9c"}