Skip to content

Browser tier

The browser tier ships Chromium (via Playwright’s headless_shell build), Playwright itself, and Node 22. Chromium starts at boot with CDP exposed on :9222 ready to drive — no display server, no X, no VNC. The right tier for scraping, programmatic CDP control, headless tests, and PDF / screenshot rendering.

Terminal window
bhatti create --name scraper --image browser --cpus 2 --memory 2048 --allow-host example.com
bhatti exec scraper -- curl -s http://localhost:9222/json/version | jq .Browser
# "Chrome/<version>"

CDP on localhost works without a guest NIC. Browsing external sites does not: use --allow-host for the required sites or --net for public egress. See Networking.

ComponentSource
Chromium (headless_shell binary)Playwright’s pinned download (~/.cache/ms-playwright/chromium-*/)
Playwrightnpm install -g playwright
Node 22NodeSource apt repo
Chromium runtime depsnpx playwright install-deps chromium

Playwright’s headless_shell is used rather than full Chrome — it’s the dedicated headless build with reliable CDP. The full Chrome binary has known CDP-attach issues in headless mode that show up as silent stream hangs.

Managed by lohar’s systemctl shim as headless-chrome.service. The unit ships with these defaults:

[Service]
Type=simple
Environment=CHROME_REMOTE_PORT=9222
Environment=CHROME_FLAGS=
EnvironmentFile=-/run/bhatti/config-env
ExecStart=/root/.cache/ms-playwright/chromium_headless_shell-<rev>/chrome-linux/headless_shell \
--no-sandbox \
--disable-gpu \
--disable-dev-shm-usage \
--remote-debugging-port=${CHROME_REMOTE_PORT} \
--remote-debugging-address=0.0.0.0 \
$CHROME_FLAGS
Restart=on-failure
RestartSec=2s

The path to headless_shell is resolved at build time by the tier script (Playwright stamps a version-suffixed directory) and baked into the unit. Operator UX is the same as every other tier:

Terminal window
bhatti exec scraper -- systemctl status headless-chrome
bhatti exec scraper -- journalctl -u headless-chrome -n 50
bhatti exec scraper -- systemctl restart headless-chrome

If Chromium crashes, the shim restarts it after 2 s. The crash + restart show up in journalctl -u headless-chrome.

CDP is HTTP + WebSocket; its debugging endpoint can control the browser. Prefer a local-only forward, not a public unauthenticated CDP URL:

9222/json/version
bhatti forward scraper 9222

Keep forward running while the client is connected. It binds the CLI machine’s loopback: your laptop’s when you run the CLI there, or the server’s when you run it on the server. For remote CDP, use an authenticated HTTPS API connection from your local CLI, or SSH to the server and tunnel its local port; don’t publicly publish CDP. See Self-hosting → Remote access.

bhatti exec runs as uid 1000 with Node and Playwright already in $PATH. Write a script as a file and exec it:

Terminal window
bhatti file write scraper /workspace/scrape.js < ./scrape.js
bhatti exec scraper -- node /workspace/scrape.js

The boot-time Chromium process listens on the guest’s port 9222. Your script can attach locally without publishing CDP. The sandbox still needs egress if its browser loads external pages.

Set at create time via bhatti create --env K=V,K=V. The values flow into the unit through lohar’s config-env bridge:

VariableDefaultEffect
CHROME_REMOTE_PORT9222CDP port to listen on
CHROME_FLAGS""Extra space-separated flags appended to ExecStart (--user-agent=…, --proxy-server=…, --lang=…, etc.)
Terminal window
bhatti create --name scraper --image browser --allow-host example.com \
--env "CHROME_FLAGS=--user-agent=Mozilla/5.0 (compatible; bhatti-bot/1.0)"

To edit flags on a running sandbox, drop a unit override and restart:

Terminal window
bhatti exec scraper -- sudo mkdir -p /etc/systemd/system/headless-chrome.service.d
bhatti exec scraper -- sudo tee /etc/systemd/system/headless-chrome.service.d/custom.conf <<'EOF'
[Service]
Environment=CHROME_FLAGS=--proxy-server=http://my-proxy:3128
EOF
bhatti exec scraper -- sudo systemctl restart headless-chrome
Workload--cpus--memory
Single-page scrapes, CDP drive11024
Concurrent Playwright tests22048
PDF rendering at scale2–42048–4096

Chromium is memory-hungry — 512 MB will OOM on any non-trivial page. The 1 GB default minimum is a real floor.

SymptomCauseFix
curl /json/version returns connection refusedChromium failed to start at bootsystemctl status headless-chrome; journalctl -u headless-chrome for the crash reason
Chromium crashed mid-sessioncrash recovered via Restart=on-failure, but flapping if it crashes repeatedlysystemctl status headless-chrome shows (activating) if currently restarting, (failed) if start-limit hit; journalctl -u headless-chrome for the underlying error
Pages OOM with Aw, Snap!Memory too lowbump --memory to 2048+
chrome-sandbox permission errors--no-sandbox got dropped from a custom drop-incheck /etc/systemd/system/headless-chrome.service.d/ — the upstream unit always passes --no-sandbox
CHROME_FLAGS not picked up--env syntax: must be comma-separated, not repeated --env flagsbhatti create --env "K1=V1,K2=V2" (single string, comma-separated)