Getting Started with Puppeteer

This article will walk you through the process of leveraging BrowserCat and Puppeteer for browser automation at scale.

Prerequisites

Before you get started, you’ll need to:

  1. Sign up for a free BrowserCat account.
  2. Create an API key.
  3. Install Puppeteer in your project…
npm install puppeteer

Your first automation

The following script connects to a BrowserCat browser, navigate to a website, and print the page title.

With a little tweaking (and the Puppeteer docs), you can automate literally anything you can do in a real browser.

import pp from 'puppeteer';

const bcatUrl = 'wss://api.browsercat.com/connect';

async function run() {
  // Create a new browser instance
  const browser = await pp.connect({
    browserWSEndpoint: bcatUrl,
    headers: {'Api-Key': '<YOUR_API_KEY>'},
  });

  // Do stuff...
  const page = await browser.newPage();
  await page.goto('https://example.com');
  console.log(await page.title());

  // Close the browser when you're done
  await browser.close();
}

run();

Configure the browser

It’s really easy to configure our browsers for your needs. Whether you want to connect to a specific region, set up a third-party proxy, or customize your browser launch args, we’ve got you covered.

See out browser config docs for more info.