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:
launch a browser locally, let’s connect to BrowserCat instead:
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. 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…
And let’s update out imports…
Notice that we preserved
playwright as a dev dependency. This ensures we can still use the CLI utility to install browsers locally.
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.