Screenshots

Browserbase enables screen view and full-screen screenshots using your desired browser automation framework with the following configuration:

Screenshot typeDPIFormat
Screen view (default)80jpeg
Full-screen90jpeg

Save a screenshot locally

A screenshot taken with Browserbase can be saved locally as a file:

PDFs

In addition to downloading files, you can also download web pages.

For playwright, you can use the page.pdf() method to download a web page as a PDF.

After creating the session, we download the page in the A4 format and save it as webpage.pdf.

Save a PDF locally

Here’s how to generate and save a PDF locally using Playwright:

Playwright
import { chromium } from "playwright-core";

(async () => {
  console.log("Starting remote browser...");
  // we connect to a Session created via the API
  const browser = await chromium.connectOverCDP(
    `wss://connect.browserbase.com?apiKey=${process.env.BROWSERBASE_API_KEY}`,
  );

  const defaultContext = browser.contexts()[0];
  const page = defaultContext.pages()[0];

  await page.goto("https://www.browserbase.com", {
    // let's make sure the page is fully loaded before taking the screenshot
    waitUntil: "domcontentloaded",
  });

  console.log("Generating PDF...");

  await page.pdf({
    path: "webpage.pdf",
    format: "A4",
  });

  console.log("Shutting down...");
  await page.close();
  await browser.close();
})().catch((error) => {
  console.error(error);
});

Downloads

Unlike screenshots and PDFs which are saved locally, files downloaded during browser automation are stored in Browserbase’s cloud storage. These files must be retrieved using our API.

A typical use case for headless browsers is downloading files from web pages. Our browsers are configured to sync any file you download to our storage infrastructure. We add a Unix timestamp onto the end of the file name to avoid naming conflicts when downloading multiple files (e.g., sample.pdf will become sample-1719265797164.pdf).

Follow these steps to download files:

  1. Use the Sessions API to create a new session. You’ll need the session ID for when you connect.
  2. Configure your library’s downloads location.
  3. Perform the download action in your automation script.
  4. Retrieve the downloaded files using the Session Downloads API.

We sync the files in real-time; the size of your downloads might affect their immediate availability through the /downloads endpoint. The above code provides a snippet to handle that use case.

Session Downloads API

Learn more about the available params and response fields

Uploads

You can easily upload files to websites using Playwright, Puppeteer, or Selenium.

Playwright

For Playwright, you can upload files directly from your local path.

  1. You’ll need your file to be available where you’re running your Playwright code.

  2. In this example, we’re using an image logo.png that’s available locally.

  3. Be sure to specify the path to your file by setting the input file.

For Puppeteer and Selenium, you’ll need to upload your files to our browser instance using our Uploads API.

  1. Use the Sessions API to create a new session. You’ll need the session ID when you upload it.

  2. Use the Session Uploads API to upload a file.

  3. Connect to the browser and the file will be available in the /tmp/.uploads directory.