Skip to main content
In this guide, we use Upstash Box to run Playwright against a JavaScript-heavy site, scrape structured data from it, and pull the results back to our own server. Because a Box is a real Linux container rather than a restricted serverless runtime, Chromium and its system dependencies install and run exactly like they would on your laptop.

1. Installation

Set your environment variables:
.env

2. Provision a box and install Playwright

Create a box with outbound network access (the default) so it can reach the target site and download the browser binaries, then install Playwright and Chromium with its system dependencies.
scripts/scrape.ts

3. Let the agent write and run the scraper

Hand the scraping task to the box’s built-in agent. It writes the Playwright script, runs it, fixes any issues it hits along the way, and saves the output to a file in the workspace.
scripts/scrape.ts
The agent has shell, filesystem, and the installed Playwright package available, so it can iterate — adjusting selectors, adding waits for dynamic content, retrying on failure — until the scrape actually produces data.

4. Pull the results back

Read the file the agent wrote and bring it back into your own process.
scripts/scrape.ts
You now have structured data extracted from a dynamic, JavaScript-rendered page — without managing a single Chromium binary yourself.

5. Skip the setup on every run with snapshots

npx playwright install chromium --with-deps takes real time to stream and unpack OS-level packages. Paying that cost on every scrape request would be painful in production. Snapshot the box once Chromium and its dependencies are installed, and restore from that snapshot whenever you need a ready-to-go scraping environment:
scripts/prepare-snapshot.ts
Store snapshot.id somewhere your application can reach (an env var, a database row, etc.), then spin up pre-warmed boxes from it on demand:
scripts/run-scrape-job.ts
Restoring from a snapshot starts the box with Chromium and its system libraries already in place, so the agent can start scraping immediately instead of waiting on apt-get and binary downloads.