Skip to content

Container sessions

Run the browser in a warm Docker container while your application keeps running the tools. Browser Harness starts or reuses one server container and gives each run its own browser connection, so concurrent runs share the container.

  • The TypeScript API installed.
  • Docker, on a trusted host. Docker access is privileged: it can start containers, mount host paths and change local infrastructure.
  1. Start a session, open a page and disconnect when done:

    import {
    startPlaywrightContainer,
    stopPlaywrightContainer,
    } from "@blopai/browser-harness";
    const session = await startPlaywrightContainer();
    try {
    const context = await session.browser.newContext();
    const page = await context.newPage();
    await page.goto("http://host.docker.internal:3000");
    } finally {
    await session.stop();
    }

    session.stop() disconnects this run and keeps the container warm. The server publishes a random port on 127.0.0.1, and host.docker.internal reaches the host.

  2. Remove the shared container when no run needs it:

    await stopPlaywrightContainer();

Use startCamoufoxContainer() and stopCamoufoxContainer() the same way, only when you need the Camoufox fingerprint. Create contexts with { viewport: null }. Without an image override, Browser Harness builds a local image matched to its versions. The server uses a random WebSocket path, and only Camoufox settings pass from the environment into the browser launch.

While a container is warm, Docker lists it:

Terminal window
docker ps --filter name=blop-playwright

When your app and the browser run in separate containers, put both on one trusted network:

Terminal window
export BLOP_PLAYWRIGHT_NETWORK=blop-network
export BLOP_CAMOUFOX_NETWORK=blop-network

The browser endpoint then uses the container name instead of a published port. Every container on that network can reach the browser server, so do not attach untrusted workloads.

VariableDefaultEffect
BLOP_PLAYWRIGHT_IMAGEmcr.microsoft.com/playwright matching the Playwright versionPlaywright image
BLOP_PLAYWRIGHT_CONTAINERblop-playwrightPlaywright container name
BLOP_PLAYWRIGHT_NETWORKunsetShared Docker network
BLOP_CONTAINER_DISABLE_CORS_BYPASSunsetAny non-empty value keeps Chromium’s same-origin enforcement on
BLOP_CAMOUFOX_IMAGElocally built imageCamoufox image
BLOP_CAMOUFOX_CONTAINERblop-camoufoxCamoufox container name
BLOP_CAMOUFOX_NETWORKBLOP_PLAYWRIGHT_NETWORKCamoufox Docker network

The Playwright container disables Chromium web security by default so runs can cross origins, for example OAuth redirects and third-party iframes. Set BLOP_CONTAINER_DISABLE_CORS_BYPASS when same-origin behaviour is part of what you test.