Getting Started with Playwright

This article will walk you through the process of leveraging BrowserCat and Playwright 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 Playwright in your project…
npm install playwright

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 Playwright docs), you can automate literally anything you can do in a real browser.

import * as pw from 'playwright';

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

async function run() {
  // Create a new browser instance
  const browser = await pw.chromium.connect(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.