Deploy Your Automations

So you’re ready to take your browser automation to production? Congrats!

The normal next step for most developers is to figure out a way to install a headless browser on their server, then figure out a way to scale it up with demand. This takes a lot of time, a lot of money, and the headaches never end.

This guide covers deploying your automation using BrowserCat instead. Rather than hosting headless browsers alongside your code, instead you’ll connect to our fleet. Your code will run faster, cheaper, at whatever scale you in, in every part of the world.

Grab a BrowserCat API key

First, sign up for BrowserCat. We’ve got a great free plan, so you may not pay anything for a very long time.

If you’ve already got an account, great! Just sign in.

Next, create an API key. Give it a nice name and a reasonable expiration date. Don’t think so hard about it. You can always change these values later.

But remember, you will only ever see the full API key this one time. If you lose it, you’ll have to create a new one.

Deploy your automation

Let’s start by deploying a basic automation.

Perhaps you’ve written a script that generates dynamic PDFs, or logs into LinkedIn as your user to send messages, or scrapes your competitors’ prices every hour. Maybe it’s a scheduled background job, or maybe it’s activated by requests to your API.

Whatever it is, you need to get the code to production.

Connect to a remote browser

Now that you’ve got an API key, let’s jump into your codebase and make the change.

Somewhere near the entry of your script, you should see a line that looks something like this:

const browser = await pw.chromium.launch();
browser = await p.chromium.launch()

Rather than launch a browser locally, let’s connect to BrowserCat instead:

const bcatUrl = 'wss://api.browsercat.com/connect';
const bcatKey = '<YOUR API KEY>';

const browser = await pw.chromium.connect(bcatUrl, {
  headers: {'Api-Key': bcatKey},
});
bcatUrl = 'wss://api.browsercat.com/connect'
bcatKey = '<YOUR API KEY>'

browser = await p.chromium.connect(
  bcatUrl, 
  headers={'Api-Key': bcatKey}
)

That’s really all there is to it. Your automation will now run in BrowserCat’s fleet, in the nearest region.

Update your dependencies

For automation scripts, Playwright offers two packages: playwright-core and playwright. The former is just the barebones needed to connect or launch a browser. The latter also includes the CLI utility required for installing browsers locally.

In “Your First Automation,” we used playwright because it’s easier to get started. But now that we’re deploying to BrowserCat, let’s switch to playwright-core. The CLI utility in playwright is an extra 300kb. No reason to ship that to production.

Let’s update out dependencies…

npm uninstall playwright
npm install playwright-core
npm install -D playwright
# No change for python

And let’s update out imports…

import * as pw from 'playwright-core';
# No change for python

# async sdk
import asyncio
from playwright.async_api import async_playwright, Playwright

# sync sdk
from playwright.sync_api import sync_playwright, Playwright

Notice that we preserved playwright as a dev dependency. This ensures we can still use the CLI utility to install browsers locally.

Next steps

Now that you’re deployed, I encourage you to explore the app dashboard. It provides realtime data about your usage. And by leveraging different API keys for different functionality, you can even use it to track costs of different features, or different environments.

And if you have any questions, contact us. We’re here to make working with the browser a joy.