Skip to content
James Ross
articlePublished Updated 7 min read

Hardened Browsers for Automation: Camoufox, CloakBrowser and Stock Playwright

By James Ross

Camoufox is a debloated Firefox build that accepts Playwright Firefox launch options. Hardened browsers for automation differ in engine, profile handling, and what you have to maintain: CloakBrowser ships a patched Chromium driven through Playwright's persistent context, and stock Playwright drives a browser you install and update yourself.

Three armored browser shells on a test bench probed by teal beams, comparing Camoufox and other hardened browsers for automation.

Camoufox, CloakBrowser and stock Playwright are the three options for the browser layer under the pipeline described in daily stock checks at big-box retailers. The differences only matter because that pipeline has to run unattended every day, for months, without someone watching it.

What does “hardened” mean in practice?

A hardened browser is one that presents a consistent, plausible client across runs and starts the same way every time. The useful properties are boring: the same engine build, the same profile, the same window size, a clean shutdown, and a visible failure when something is wrong.

It is not a guarantee. Any site can refuse automation, and when it does the correct response is to record the refusal and stop, not to escalate. The value of a hardened build is that a legitimate daily check produces the page a customer would see, without the browser being the variable that changed.

That framing matters because the three options are often compared as if the choice were about passing a gate. The choice that actually matters is maintenance: which browser your team can update, how it stores sessions, and what happens when it crashes at 3 a.m.

Why is a persistent context the whole game?

A persistent context keeps one profile directory — cookies, local storage, cache, and service workers — attached to every launch, so a session established once survives restarts. That single property decides whether a daily job is reliable.

Playwright’s default model is the opposite: browser.newContext() creates an isolated context that shares no cookies or cache with other contexts (Playwright: Browser contexts). That is the right default for tests and parallel work, and the wrong one for a job that needs to stay logged in.

With launchPersistentContext, the profile lives on disk and the browser picks it up at launch. Four rules keep it healthy:

  1. One profile per target site. Two sites in one profile leak state and make failures impossible to attribute.
  2. Never point it at an everyday browser profile. Concurrent access locks the profile’s own databases and can corrupt session state.
  3. Close the context, do not kill the process. Closing flushes cookies and storage to disk. Killing can leave a lock file behind.
  4. Recycle on a schedule. A restart every few dozen pages keeps memory flat and converts a slow leak into a planned event.

How do the three options compare?

They occupy different points on the same line: how much of the browser do you want the vendor to own?

CloakBrowser Camoufox Stock Playwright
Engine patched Chromium debloated Firefox Chromium, Firefox or WebKit, pinned by Playwright
Driver Playwright over a pipe, no debugging port by default Playwright Firefox API over Juggler Playwright over CDP for Chromium
Profile model launchPersistentContext persistent_context=True with user_data_dir launchPersistentContext, or your own storage state
Browser updates vendor build, downloaded and checksum-verified vendor build, versioned and selectable on launch playwright install, pinned to the library version
Footprint patched Chromium plus a ~150 MB download about 200 MB, headless-first a full browser install per engine
Tooling that needs CDP needs a second Chromium needs a second Chromium works
Best for long-lived sessions on a strict site Firefox-side consistency at a smaller footprint apps you own and sites that behave

Which should you choose? Use stock Playwright when you control the page or the site is tolerant, because it has the smallest dependency surface and the best tooling. Use CloakBrowser when a site expects a specific Chromium build and your sessions live for weeks, and you accept that the vendor owns the browser binary. Use Camoufox when you want a Firefox engine, a smaller footprint, and headless-first behaviour with Playwright’s launch options. In all three cases, pick the one your team can patch on a Tuesday.

CloakBrowser: a patched Chromium behind Playwright

CloakBrowser is a Chromium distribution with patches applied at the source level, launched by Playwright through a persistent context. In the fork used here, the browser layer was rewritten to call launchPersistentContext instead of attaching to a system Chrome instance over the DevTools protocol (CloakBrowser).

The practical consequences are concrete. There is no remote debugging port open by default, which removes a piece of surface but also removes a piece of tooling. The binary is downloaded, cached, and checksum-verified per platform, so the first launch on a new machine needs network access and about 150 MB of disk. After that, the same build starts every time, which is the property that matters for a long-lived session.

It is the right default when the site is strict about which browser it sees and the job needs one identity for weeks. It is the wrong default for a quick script, because you have added a vendor, a download step, and a build you do not compile.

Camoufox: debloated Firefox on Playwright’s Firefox API

Camoufox is a Firefox build stripped of telemetry, background services, and UI overhead, with the stated goal of running many browser instances on one machine. The project quotes roughly 200 MB against 800 MB or more for Chrome, and it is headless-first by design (Camoufox).

Camoufox was the browser layer in a separate competitor-price build, next to Playwright and a schema-validated extractor (from the project record). The migration cost is close to zero if the code already uses Playwright’s Firefox API. Camoufox accepts Playwright Firefox launch options and adds its own, including device and locale generation, humanize for cursor movement, headless="virtual" to use a virtual display on Linux, and persistent_context with user_data_dir (Camoufox usage).

The trade-off is the engine. Camoufox drives Firefox over Juggler rather than CDP, so tooling built around Chromium’s debugging protocol will not attach. If a pipeline depends on CDP for tracing, network interception, or a Lighthouse run, that dependency has to move or the browser choice has to change.

Stock Playwright: you own the browser

Stock Playwright is the least magical option and often the correct one. Playwright installs pinned browser builds, keeps them in a cache, and launches them with a version that matches the library (Playwright: Browsers). Nothing is patched, so whatever the site sees is what the browser actually is.

The advantages are maintenance and tooling: a security update is a version bump, the debugging protocol works, and every tracing and inspection tool in the ecosystem attaches. The disadvantage is that the browser is a generic build with a generic automation surface, and some sites treat that as a reason to refuse.

For apps you own, internal QA, and most public sites, that trade is easy. For a site that refuses generic automation, stock Playwright is the option that fails first — which is useful information, not a defect.

What is the maintenance and footprint cost?

The browser binary is the smallest part of the cost. Once a container includes the browser, its shared libraries, fonts, and a virtual display for headed runs, the image grows by hundreds of megabytes, and every rebuild pays for it.

Three costs dominate over a year:

  • Update cadence. A patched build ships when the vendor ships it. Stock Playwright ships when you bump the version. Either way, an unpatched browser is a security problem, so the update path has to be someone’s job.
  • Debugging surface. A browser with no debugging port is harder to inspect when a page misbehaves. The team needs a fallback: a headed run, a screenshot, or a second browser for diagnosis.
  • Session recovery. Persistent profiles accumulate state. A profile that has been running for months will eventually hold a cookie or a cache entry that breaks a page, and the fix is a clean profile and a fresh login.

What broke and what we changed

An interrupted login left the profile locked. A login helper used to hang until it was interrupted, which left the profile locked and surfaced later as a message about an existing browser session. Closing the context is what flushes cookies and storage, so the helper now detects the captured session, flushes, and exits on its own.

Pointing the profile at an everyday browser corrupts it. The guidance is explicit: never aim userDataDir at a primary Chrome profile, because simultaneous access locks its databases and corrupts session state. A dedicated directory per automation target avoids the whole class of failure.

One stuck job blocked the shared context. With a single persistent context, a job that reached a manual-action state and never cleared left the queue’s current job set. Every later request waited behind it until the process restarted. The fix was a reset path that clears the stuck job without restarting the browser, plus a timeout that fires before the queue backs up.

No debugging port broke the Lighthouse step. A crawler service renders with the patched Chromium, but Lighthouse cannot attach to a browser that exposes no debugging port. The image therefore also contains a stock Chrome for Lighthouse, and the fallback is logged rather than silent.

A widget below the fold needed a taller display. The same lesson showed up in a stock checker: the availability box lazy-renders below the fold, which is why the virtual display had to be 1400×1600. Headless-first is a fine default, but the viewport and the scroll position are part of the extraction contract.

Frequently asked questions

Is CloakBrowser better than Playwright?

Neither is better in general. CloakBrowser is a browser distribution with patches; Playwright is the automation library that drives it. The comparison that matters is CloakBrowser against the stock Chromium that Playwright installs, and the answer depends on whether a site refuses the stock build and whether you want a vendor owning the binary.

Does Camoufox work with existing Playwright code?

Mostly, yes. Camoufox is fully compatible with Playwright's Firefox API, so the change is usually the browser initialisation line rather than the page code. Launch options specific to Camoufox, such as device generation and persistent context, are passed at construction. Code that depends on Chromium-only features, including CDP sessions, will not carry over unchanged.

Why does a persistent browser profile get locked?

A lock file in the profile directory stops two processes from writing the same profile at once. If a browser is killed rather than closed, the lock can survive and the next launch refuses to start. The fix is to close the context and, when that is impossible, to remove the stale lock after confirming no browser process is still using the directory.

How much memory does a headless browser use?

There is no fixed number, because memory follows the page rather than the browser. Camoufox's project quotes about 200 MB for the browser itself against 800 MB or more for Chrome, and a loaded application page adds to either figure. That baseline is what matters when several instances share one machine.

Can these browsers run in Docker?

Yes, and all three need the same care: the image must include the browser's shared libraries and fonts, a headed run needs a virtual display, and the profile directory must be on a mounted volume if it has to survive a redeploy. A browser that runs on a laptop and fails in a container is usually missing a library or a display, not a flag.

Which browser is best for long-running sessions?

The one whose update path you can live with. CloakBrowser is built for a long-lived persistent context and a consistent build, Camoufox is built for many lightweight instances, and stock Playwright is built for control. Reliability comes from the profile handling and the restart policy more than from the engine.

Do you need a different browser for each site?

No, but you need a different profile for each site. One browser build can serve every target; sharing a profile across targets is what causes cross-contamination. Keep the build shared and the profiles separate, and most attribution problems disappear. Separate profiles also make a failure easy to trace to one site.