Skip to content

Quick start

  1. Start it.

    Terminal window
    export BROWSERBAY_API_KEY="$(openssl rand -base64 24)" # keep it: your projects present it
    docker run -d --name browserbay --restart always --init --stop-timeout 130 \
    -p 127.0.0.1:8788:8788 -e BROWSERBAY_API_KEY \
    ghcr.io/degoke/browserbay

    That one container is a complete box: the relay and a Chromium node together. It listens on this machine only (127.0.0.1). --stop-timeout 130 is the 120 seconds a stopping node gives slots in use, plus a margin. On Kubernetes, use the Helm chart instead.

  2. Check it is up.

    Terminal window
    curl http://127.0.0.1:8788/health
    curl -H "Authorization: Bearer $BROWSERBAY_API_KEY" http://127.0.0.1:8788/v1/nodes

    /health says the relay is up. /v1/nodes shows the Chromium node and how many slots it has free.

It is published on npm as @degoke/browserbay, already built, so installing it needs no registry setup and no token:

Terminal window
pnpm add @degoke/browserbay playwright

Every release is also on GitHub Packages. To install from there, point the @degoke scope at https://npm.pkg.github.com in .npmrc and use a personal access token with read:packages.

Use the scoped name. An unscoped npx browserbay is not this package: the command is npx @degoke/browserbay.

import { chromium } from 'playwright'
import { createBrowserBay } from '@degoke/browserbay/client'
const box = createBrowserBay({
url: 'http://127.0.0.1:8788',
apiKey: process.env.BROWSERBAY_API_KEY
})
const slot = await box.acquire({ runId: 'task-42', maxLifetimeSeconds: 30 * 60 })
try {
const browser = await chromium.connectOverCDP(slot.cdpUrl, { headers: slot.headers })
const context = browser.contexts()[0] // your slot's context: use it, do not create another
const page = context.pages()[0] ?? (await context.newPage())
await page.goto('https://example.com')
console.log(await page.title())
} finally {
await slot.release()
}

acquire waits up to 30 seconds for a free slot and fails with a no-capacity error if the box stays full. The maximum lifetime is the lease: the browser closes itself after that long even if your process crashed. See Concepts for the vocabulary and Drive a browser for Puppeteer and plain DevTools.