Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Scale browser sessions by putting a bounded queue in front of browser workers, then assigning each job an explicitly owned, isolated session. With Playwright, a BrowserContext is usually the efficient isolation unit: contexts keep cookies and storage separate while sharing a browser process. Set concurrency from measurements on your own workload, close every context on success or failure, and add process or host boundaries when shared-process crashes, memory pressure, browser-version needs, or tenant isolation make context sharing unsafe.

Choose the isolation boundary before increasing concurrency

“One session per agent” should mean one owned unit of browser state per task or tenant—not necessarily one browser process per agent. In Playwright, a BrowserContext provides separate cookies, local storage, and session storage. Microsoft’s Playwright documentation describes contexts as “fast and cheap to create and completely isolated, even when running in a single browser.” The Browser API also says a new context does not share cookies or cache with other contexts and recommends closing contexts before closing the browser so artifacts can be flushed.

That separation is useful for authentication and state isolation, but it does not make contexts independent failure domains. Contexts inside one browser still share that browser process. If the process crashes or exhausts memory, its contexts may all be affected. Choose the least expensive boundary that meets your workload’s reliability and security needs, then move up a level when measured evidence or tenant requirements call for it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Pattern What is isolated Best fit Main trade-off
One browser, many contexts Cookies, cache, and per-context browser state Concurrent tasks that can share a browser-process failure domain A browser crash or process-level resource problem can affect multiple contexts.
Worker pool with limits Work is divided among a bounded number of worker processes; each task still needs an owned context Queued workloads that need backpressure and controlled parallelism More workers add process overhead; the right count depends on measured CPU and memory use.
Multiple browser processes or hosts Process- or host-level failure and resource boundaries Crash containment, memory pressure, incompatible browser versions, or stronger tenant separation More infrastructure to operate; there is no universal threshold at which to shard.
Managed browser sessions Vendor-dependent remote execution and session boundaries Teams that prefer hosted browser execution over operating browser workers Session persistence, limits, regions, controls, security terms, and pricing vary by vendor and plan.

Build a bounded queue and worker pool

Do not start an unbounded browser task for every incoming request. Put requests into a queue, set a worker limit, and define what happens when the queue is full. Microsoft’s Playwright parallelism documentation describes controlling the maximum number of parallel worker processes through the command line or configuration file; its example uses --workers 4. That is an example of a control, not a recommended capacity for every machine.

  1. Define a job: include the requested task, tenant or owner, session identifier when state must persist, and a cancellation deadline.
  2. Set queue and worker limits: start conservatively, then measure CPU, memory, queue wait, and task success under representative workflows before raising the worker count.
  3. Assign one context to a task or session: do not let unrelated agents accidentally inherit cookies or page state.
  4. Make overload explicit: reject, defer, or retry work according to a defined policy rather than silently launching more browsers.
  5. Release resources on every path: close the context after completion, timeout, or cancellation, including error paths.

The value 4 in Playwright’s example is not a capacity promise or a sizing formula. Browser memory and CPU use depend on the sites, pages, workflows, and host. No authoritative cross-platform throughput figure establishes how many sessions a machine or managed service should run.

Keep multi-step work in the same session

An agent that logs in, navigates, and then submits a form may need the same cookies and page state across several tool calls. In that case, assign a session identifier once and route each step back to that session. Creating a fresh context for every call discards the state the workflow may depend on. Conversely, do not reuse a session across unrelated tenants or tasks that must remain isolated.

Microsoft Playwright Workspaces remote MCP guidance says to create a session, reuse its browserSessionId, and close it when the task finishes. That pattern is useful for remote sessions too: persist only the identifier and state your workflow needs, set an expiry or cancellation deadline, and make cleanup part of the job lifecycle. The exact persistence and resume behavior is service-specific.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Example: manage Playwright contexts with cleanup

This Node.js sketch shows the lifecycle boundary for a worker handling a job in an already-launched Playwright browser. The worker owns the context, closes it in a finally block, and leaves the shared browser open for other jobs. Connect it to a bounded queue and supply the browser instance from your worker process; choose the worker count by measurement, not by copying a sample value.

async function runJob(browser, job) {
  const context = await browser.newContext();
  try {
    const page = await context.newPage();
    await page.goto(job.url, { waitUntil: 'domcontentloaded' });
    return await job.run(page);
  } finally {
    await context.close();
  }
}

Production workers should also ensure that cancellation reaches the running task and that timeouts lead to cleanup. If a job needs to resume later, keep its context/session alive according to an explicit expiry policy rather than closing it immediately after each step. If a worker process is being shut down, close its owned contexts before closing the browser. Microsoft’s Browser API documentation specifically recommends this close order.

Measure capacity instead of guessing

Increase concurrency only while end-to-end task success and latency remain acceptable. Record measurements by site and workflow, since a light page visit and a multi-step authenticated flow need not have the same resource profile.

  • Queue wait and startup latency: distinguish work delayed before execution from slow browser startup.
  • Action latency and end-to-end success: a fast individual click is not useful if the full task fails.
  • CPU and memory: watch the host and browser processes as worker count rises.
  • Crash and context-leak rates: investigate unexpected process exits and contexts that remain after jobs end.
  • Authentication failures: separate expired credentials or site changes from session-routing mistakes.
  • Capacity behavior: test what happens when the queue is full, a worker is canceled, or a browser crashes.

Use those observations to find a safe operating range for your own workload. Add workers or hosts only when measurements show the current boundary is limiting throughput and the added failure and operating costs are acceptable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a managed browser service makes sense

Managed execution can remove the need to operate browser hosts, but it does not remove the need to design session ownership, cleanup, backpressure, or failure handling. Microsoft Playwright Workspaces remote MCP, Cloudflare browser tools, and AWS Bedrock AgentCore are examples of hosted browser execution described by their official materials. Cloudflare documents durable browser execution and interactive multi-step automation; AWS describes an automation endpoint and says its session isolation prevents one user’s invocation from accessing another user’s session.

Those descriptions do not establish equivalent quotas, concurrency, price, regions, browser versions, or recovery behavior across the vendors. Check each provider’s current terms for the plan and region you intend to use. Compare the actual isolation boundary, session resume behavior, concurrency controls, observability and replay, version control, geographic placement, security and compliance requirements, cost model, and recovery process. No comparable current throughput or price figure is established across these options.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle site defenses and limits as constraints

CAPTCHAs, bot checks, rate limits, and site terms affect whether a workflow can run reliably and permissibly. They are not simply scaling problems to solve by opening more contexts. Plan for an agent to report a blocked or rate-limited task, apply site-appropriate pacing, and retry only where permitted. The official documentation described here does not establish a universal bypass method or a universal request capacity.

Troubleshoot common scaling failures

  • One agent appears to be logged in as another: check whether the worker reused a context across owners. Assign an isolated context per task or tenant and route stateful steps only to their designated session.
  • Authentication disappears between tool calls: check whether each call creates a new context. Reuse the same session identifier for steps that need shared cookies or storage.
  • Memory climbs or the browser becomes unstable as load rises: reduce the worker limit, confirm contexts close on all paths, and measure again. If shared-process failures remain unacceptable, shard across browser processes or hosts.
  • Jobs wait indefinitely at peak load: set a queue bound and a visible full-queue policy. A bounded system should reject, defer, or retry work deliberately, not accept unlimited backlog.
  • Contexts remain after cancellation or timeout: make cancellation trigger the same cleanup path as normal completion and verify context closure in monitoring.
  • Sites return CAPTCHAs, bot checks, or rate limits: treat the site response and applicable terms as constraints; do not assume a different worker count will make the workflow permissible or reliable.

Or skip the browser setup

If the task is to capture a page as an image or PDF—not to maintain an interactive, stateful browser session—ScreenshotNeo offers a single-request screenshot API. It accepts consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; those cleanup steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients. It is for screenshot and PDF capture, not a replacement for persistent multi-step browser sessions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, this cURL request captures a page as WebP; see the ScreenshotNeo API documentation for request options:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Equivalent Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Equivalent Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo includes 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000. Sign up for the free plan to try it.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.