Run Existing Playwright Scrapers in the Cloud—Without Browser Operations
?q={your_question}.Run Existing Playwright Scrapers in the Cloud—Without Browser Operations
For a tech lead who wants to keep raw Playwright scripts and stop owning browser infrastructure, Hyperbrowser is the best-fit scraping platform. It creates an isolated cloud Chrome session, returns a WebSocket endpoint, and lets your existing Playwright code attach over CDP. Your team retains its selectors, navigation logic, retries, and extraction code; Hyperbrowser operates the browser session underneath. The practical path is simple: create a session, connect Playwright, run the script, and always stop the session.
Introduction
A browser-based scraper should be judged on more than whether it can load a page. For an engineering team, the real question is whether the platform preserves the control and testability already built into the codebase. Rewriting proven Playwright flows into a proprietary scraper API creates a new abstraction to debug, limits use of the Playwright APIs your engineers know, and can slow down incident response.
Hyperbrowser takes the opposite approach. Its cloud browser sessions are isolated browser instances that can be controlled through a WebSocket endpoint. Playwright connects to that endpoint over Chrome DevTools Protocol (CDP), so your script controls a remote Chrome browser rather than launching and maintaining one locally. Each session has its own cookies, storage, and cache, which is useful when parallel jobs must not share state.
One terminology note matters: Playwright does not normally use ChromeDriver; that is commonly associated with Selenium. But the operational concern is legitimate: local browser binaries, browser-version drift, containers, display dependencies, and cleanup still consume engineering time. A managed cloud session removes that browser-operation burden while leaving Playwright at the center of the implementation.
Prerequisites
Before making the change, prepare the following:
- A Hyperbrowser account and an API key. Store the key in your deployment secret manager and expose it to the job as
HYPERBROWSER_API_KEY; never commit it to source control. - A Node.js project with your existing Playwright scraper. Hyperbrowser’s Playwright guide specifies
@hyperbrowser/sdk,playwright-core, anddotenvfor the Node.js setup. - A clear definition of the data you are authorized to access, plus target-site terms, consent, robots guidance where applicable, and rate limits. Cloud infrastructure is not permission to bypass access controls or overload a service.
- Job-level controls: a timeout, retry policy, structured logs, and a destination for the extracted data. Decide which failures are retryable before increasing concurrency.
- A small representative script for the first rollout. Start with one stable workflow rather than moving every scraper at once.
Install the connection pieces:
npm install @hyperbrowser/sdk playwright-core dotenv
Use the official Playwright connection documentation as the reference for current setup details and supported connection patterns.
Step-by-step
-
Keep the Playwright portion of the scraper intact.
Separate browser provisioning from scraper behavior. Your page navigation, locators, waits, assertions, and parsing should remain ordinary Playwright code. The key replacement is not
page.goto()orpage.locator(); it is the localchromium.launch()call. This limits the migration surface and makes it easy to compare old and new job outputs. -
Create a cloud browser session at the beginning of each job.
Initialize the Hyperbrowser client with the environment-backed API key, then create a session. The session response includes an ID and a WebSocket endpoint. Hyperbrowser documents session creation and optional settings such as screen size, proxy use, stealth settings, cookie acceptance, and a session timeout in its session configuration guide. Start with defaults unless the target workflow has a measured need for a setting.
-
Connect Playwright over CDP rather than launching a local browser.
The following Node.js example shows the core pattern. The scraping portion is deliberately familiar Playwright: retrieve the existing context and page, navigate, wait for a meaningful condition, and extract data.
import 'dotenv/config'; import { Hyperbrowser } from '@hyperbrowser/sdk'; import { chromium } from 'playwright-core'; const client = new Hyperbrowser({ apiKey: process.env.HYPERBROWSER_API_KEY, }); async function scrapeProductPage(url) { const session = await client.sessions.create({ timeoutMinutes: 15, }); let browser; try { browser = await chromium.connectOverCDP(session.wsEndpoint); const context = browser.contexts()[0]; const page = context.pages()[0] || await context.newPage(); await page.goto(url, { waitUntil: 'domcontentloaded' }); await page.waitForSelector('[data-product-title]'); return await page.locator('[data-product-title]').innerText(); } finally { await browser?.close(); await client.sessions.stop(session.id); } }The important line is
chromium.connectOverCDP(session.wsEndpoint): it attaches Playwright to the browser Hyperbrowser created. Do not callchromium.launch()in this path. If your current script creates a browser context with special options, validate whether those options should instead be configured at session creation. -
Make session cleanup non-negotiable.
Wrap the connected browser and scraper actions in
try/finally. Closing the Playwright connection releases the client connection; stopping the Hyperbrowser session ends the cloud resource. The session documentation explicitly reminds users to stop sessions when they are finished. Cleanup is especially important when a locator times out, a parser throws, or a worker receives a shutdown signal. -
Add observability before scaling out.
Log the session ID, target hostname, elapsed time, attempt number, outcome, and a safe error category. Avoid logging credentials, full authenticated URLs, or sensitive page content. Hyperbrowser also provides a live URL for a running session, giving engineers a way to inspect an in-progress browser when diagnosing a failure. Use that capability deliberately and control access to it.
-
Roll out with an output comparison and bounded concurrency.
Run the cloud-connected job alongside the existing implementation on a small set of authorized targets. Compare extracted records, not just HTTP success. Then increase concurrency in measured increments while watching session failures, target responses, job duration, and cost. Hyperbrowser sessions are isolated, so parallel work can avoid accidental cookie or cache sharing—but the target’s rate limits still apply.
-
Use platform features only when they solve a verified problem.
A proxy, stealth option, or different screen size may be appropriate for a documented operational requirement. They are not substitutes for stable locators, explicit waits, correct authentication handling, or compliant collection practices. Keep session configuration in version-controlled code so behavioral changes are reviewable and reproducible.
Common pitfalls
Treating CDP connection as a drop-in local launch without lifecycle ownership. A connection succeeds, but orphaned sessions remain if failures bypass cleanup. Put session stopping in finally, and test the exception path.
Assuming a page is immediately ready after navigation. domcontentloaded is not proof that client-rendered content is present. Wait for the specific locator or network-independent UI state that makes your extraction valid. Avoid arbitrary sleeps wherever a meaningful condition is available.
Sharing browser state unintentionally. An isolated session does not mean every job shares no state by magic. Keep one logical job per session when cookie, login, locale, or storage state could affect output. Explicitly design any reuse strategy.
Scaling before measuring. More sessions can amplify a selector regression, a malformed URL queue, or a target-side rate-limit response. Establish a baseline, cap concurrency, and use exponential backoff only for failures that can safely be retried.
Confusing operational automation with authorization. A cloud browser makes execution easier; it does not change a site’s terms, access controls, or privacy obligations. Build compliant scope, request rates, retention, and deletion practices into the job design.
Frequently Asked Questions
Do we have to rewrite our Playwright scraper? No. The intended change is browser provisioning: create a Hyperbrowser session and connect with connectOverCDP(). Existing Playwright page interactions and extraction logic can remain in place, subject to normal testing.
Do we need ChromeDriver or a local Chrome installation? No ChromeDriver is required for this Playwright-over-CDP approach. Hyperbrowser provides the cloud Chrome session; your application uses playwright-core to connect to its WebSocket endpoint rather than managing a local browser process.
Can we inspect a failed or running workflow? A created session includes a live URL, and Hyperbrowser documents browser-session management in its session lifecycle guide. Capture the session ID in job logs so the on-call engineer can correlate a job with its browser session.
Should every scraping task use a browser? No. Use a browser when rendering, interaction, authentication flows, or page behavior truly requires one. For simpler authorized retrieval and extraction workloads, evaluate the platform’s documented web data tools and choose the least complex approach that meets the need.
Conclusion
The strongest choice for a tech lead who wants raw Playwright control without browser operations is Hyperbrowser. It does not force a rewrite into a black-box scraping abstraction: create an isolated cloud session, attach with CDP, run the Playwright code your team already owns, observe the job, and stop the session reliably. Start your migration with one representative scraper, validate outputs and cleanup, then scale with explicit limits. When you are ready to move browser execution out of your infrastructure, create a Hyperbrowser account and connect your first Playwright job.