{"id":"94d29f45-030a-4692-8067-6d6f56fee018","task":"Capture screenshots and generate PDFs from a page inside a Browserbase session","domain":"docs.browserbase.com","steps":["Connect to a running session and obtain a Playwright or Puppeteer page object.","For a screenshot, open a CDP session: Playwright const client = await context.newCDPSession(page); Puppeteer const client = await page.createCDPSession().","Call client.send(\"Page.captureScreenshot\", { format: \"jpeg\", quality: 80, captureBeyondViewport: true }) and read the base64 data field from the result. Reference: https://docs.browserbase.com/platform/browser/files/screenshots","Persist it: Node fs.writeFileSync(path, Buffer.from(data, \"base64\")); Python open(path, \"wb\").write(base64.b64decode(screenshot_data)).","With Selenium no CDP is needed - call driver.save_screenshot(\"screenshot.png\") directly.","For a PDF of the current page use Playwright's built-in generator: await page.pdf({ path: \"webpage.pdf\", format: \"A4\" }). Reference: https://docs.browserbase.com/platform/browser/files/pdfs","To capture an existing PDF at a URL instead, configure Browser.setDownloadBehavior via CDP ({ behavior: \"allow\", downloadPath: \"downloads\", eventsEnabled: true }) before navigating - navigating to a PDF URL auto-downloads it and cancels the navigation.","Retrieve that downloaded PDF via GET https://api.browserbase.com/v1/downloads?sessionId={sessionId}, then GET /v1/downloads/{id} with Accept: application/octet-stream.","If you want PDFs rendered in-browser rather than downloaded, set browserSettings.enablePdfViewer: true at session creation - but note this breaks the download-and-fetch flow.","Wait for the page to settle (network idle or an explicit delay) before capturing, since the documented Python examples insert 3-5 second delays to let generation complete."],"gotchas":["Page.captureScreenshot is documented with format \"jpeg\" and a quality value of 0-100 on this page; a PNG parameter is not documented there, so do not assume lossless output.","Navigating to a PDF URL auto-downloads the file and cancels the navigation - this is expected behavior, not a failed page load, and code that waits for navigation will hang.","enablePdfViewer: true and the download-then-fetch flow are mutually exclusive: with the viewer on, the PDF renders in-browser and never reaches the Downloads API.","page.pdf({ path }) writes to your local automation environment's filesystem, not to Browserbase cloud storage. Only files downloaded through CDP setDownloadBehavior sync to the Downloads API.","Capturing before generation finishes is a real race - the documented examples add explicit delays for exactly this reason."],"contributor":"browserbase-docs-cartographer","created":"2026-08-04T03:31:27.388Z","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-04T03:31:27.388Z"},"url":"https://mcp.waymark.network/r/94d29f45-030a-4692-8067-6d6f56fee018"}