Where does a Playwright script run when the browser it controls is in the cloud? In my DevMorph experiment, Node.js ran on my computer. A remote Chromium browser opened the DevMorph site, clicked Projects, scrolled through the page, and returned a screenshot that my script saved locally.

That split is useful when the browser needs to run in a specific network environment or when several teams need more browser capacity than their existing runners can provide. For a quick check during development, a browser on your own machine is often enough. This guide shows how to connect Playwright to a cloud browser with GoLogin, verify a page before capturing it, and decide where the browser should run in your own workflow.

What Playwright does in a browser automation workflow

Browser automation uses code to perform actions a person would normally carry out in a browser. A script can follow a navigation path, fill a form on a test environment, or collect screenshots after a deployment. A monitoring job can visit a public page periodically and report when an expected element fails to appear. Each job needs its own definition of success. A screenshot is useful evidence, and a URL or content assertion gives the job a result it can check automatically.

Playwright provides APIs for navigating pages, finding elements, and capturing what the browser renders. Its library works for standalone scripts such as this one. Playwright Test adds a runner, assertions, reporting, and fixtures for suites. Playwright supports Chromium, Firefox, and WebKit when you use the corresponding browser engines. The CDP connection in this guide targets Chromium.

Local vs. cloud browsers

In a local setup, the script launches a browser on the same machine. That machine can be your laptop or an ordinary CI runner. In a managed setup, the browser process runs on a provider’s infrastructure while the script connects from another machine. You can also host the remote browser yourself if your team needs control over networking, maintenance, and data handling.

Factor Browser on your machine or CI runner Browser on a managed service
Execution The script and browser share a host. The browser runs on provider infrastructure. The script can run locally or in CI.
Setup Install browsers and system dependencies on the runner. Configure access, a remote endpoint, and any team or profile settings.
Cost Budget for machine capacity, CI time, and maintenance. Check plan fees, browser time, concurrent sessions, and any extras.
Latency No remote control connection. The browser still makes network requests to the site. Session startup and control round trips add overhead. Page timing also depends on the browser’s location.
Scale Add workers or shard the suite across CI jobs. Provision sessions up to provider quotas, with a plan for queuing excess work.
Debugging Open a visible browser or inspect Playwright traces from CI. Use session logs, recordings, or live views where available.
Reliability The team manages browser versions, runner health, and capacity. Runs also depend on the provider and remote connection.
Security The team controls where credentials and test artifacts are stored. Review provider access, network boundaries, and profile or recording retention.
Good fit Development feedback, private staging, and routine regression tests. Region-specific checks, bursts of browser work, or shared browser infrastructure.
Local execution with Node.js and Chromium on the same host compared with remote execution over CDP.
Local and remote browser execution architectures.

How a remote browser returns a local screenshot

The Node.js script opens a secure WebSocket connection to the provider. Playwright sends browser commands over the Chrome DevTools Protocol (CDP). The remote browser fetches and renders the website, executes the requested actions, and returns screenshot data. When the script supplies a local path to page.screenshot(), Playwright saves the result on the machine running Node.js.

chromium.connectOverCDP() attaches to an existing Chromium-based browser. Playwright documents that CDP supports fewer features than its native Playwright protocol connection. Confirm compatibility for any advanced features your suite uses before migrating it. Also keep the two network paths in mind. A nearby target server can make pages load quickly from the cloud browser while the script’s connection to that browser still has noticeable command latency.

Local Node.js and Playwright send commands over a secure WebSocket and CDP to a remote Chromium browser, which accesses a website and returns screenshot data.
The script runs locally, while the browser executes remotely.

Connect Playwright to GoLogin Cloud Browser

The example below recreates the main actions of my DevMorph experiment. It’s a separate tutorial implementation. Start with a dedicated test profile, a GoLogin account with Cloud Browser API access, and a current Node.js LTS release. The Cloud Browser dashboard shows where to find the API token and check your account’s limits. Use the ID of a profile your account can run in the cloud.

1. Install the Node.js dependency

Open a terminal and create a project folder. The .mjs extension tells Node.js to load the script as an ES module. This example uses playwright-core because the provider supplies the remote Chromium process.

mkdir devmorph-cloud-browser
cd devmorph-cloud-browser
npm init -y
npm install --save-exact playwright-core

2. Configure the token and profile

Create a .env file in the project folder. Replace the placeholders on your machine. Node loads the file with --env-file. An existing environment variable takes precedence over the corresponding value in the file. In CI, store credentials in the platform’s secret manager.

GOLOGIN_TOKEN=replace_with_your_cloud_browser_api_token
GOLOGIN_PROFILE_ID=replace_with_your_test_profile_id

Add these entries to .gitignore before creating a real credential file or capturing screenshots. Keep your package lockfile so teammates and CI can install the same dependency version.

node_modules/
.env
artifacts/

3. Connect, navigate, scroll, and capture

Save the following as demo.mjs. The endpoint, query parameter names, and default browser context follow the GoLogin Cloud Browser connection example. The script creates its own tab in the configured profile, uses the public Projects navigation link, then checks both the URL and the heading before writing the artifact.

import { mkdir } from 'node:fs/promises';
import { chromium } from 'playwright-core';

const token = process.env.GOLOGIN_TOKEN?.trim();
const profileId = process.env.GOLOGIN_PROFILE_ID?.trim();

if (!token || !profileId) {
  console.error('Set GOLOGIN_TOKEN and GOLOGIN_PROFILE_ID in .env.');
  process.exit(1);
}

const endpoint = new URL('wss://cloudbrowser.gologin.com/connect');
endpoint.searchParams.set('token', token);
endpoint.searchParams.set('profile', profileId);

let browser;
let page;
let stage = 'connect to the cloud browser';

try {
  browser = await chromium.connectOverCDP(endpoint.href, {
    timeout: 30_000,
  });

  stage = 'open a page in the configured profile';
  const [context] = browser.contexts();
  if (!context) throw new Error('The expected browser context is missing.');

  page = await context.newPage();
  page.setDefaultTimeout(15_000);
  page.setDefaultNavigationTimeout(30_000);
  await page.setViewportSize({ width: 1280, height: 720 });

  stage = 'load the DevMorph homepage';
  const response = await page.goto('https://www.devmorph.dev/', {
    waitUntil: 'domcontentloaded',
  });
  if (!response?.ok()) throw new Error('The homepage did not return 2xx.');

  stage = 'open and verify the Projects page';
  await page.getByRole('link', { name: 'Projects', exact: true })
    .first()
    .click();
  await page.waitForURL(url =>
    ['www.devmorph.dev', 'devmorph.dev'].includes(url.hostname)
      && /^\/projects\/?$/.test(url.pathname)
  );
  await page.getByRole('heading', {
    level: 1,
    name: 'Software Built for Real Business Problems',
  }).waitFor({ state: 'visible' });

  stage = 'scroll and save the screenshot';
  await page.evaluate(() => window.scrollTo({
    top: document.documentElement.scrollHeight,
    behavior: 'instant',
  }));
  await mkdir('artifacts', { recursive: true });
  await page.screenshot({
    path: 'artifacts/devmorph-projects.png',
    fullPage: true,
    animations: 'disabled',
    timeout: 20_000,
  });
  console.log('Saved artifacts/devmorph-projects.png');
} catch (error) {
  // Connection errors can include the token-bearing WebSocket URL.
  const detail = error?.name === 'TimeoutError' ? ' Timed out.' : '';
  console.error(`Could not ${stage}.${detail}`);
  process.exitCode = 1;
} finally {
  try {
    await page?.close();
  } catch {
    console.error('Could not close the tab cleanly.');
    process.exitCode = 1;
  }

  try {
    await browser?.close();
  } catch {
    console.error('Could not close the connection. Check the cloud dashboard.');
    process.exitCode = 1;
  }
}
node --env-file=.env demo.mjs

On success, open artifacts/devmorph-projects.png in the project directory. The full-page screenshot captures the document beyond the viewport. The explicit scroll is useful for exercising the page’s behavior. For pages that fetch content after scrolling, wait for the specific item or response you need before capturing. A scroll by itself doesn’t establish that new content finished loading.

If the connection fails, check account access, the token, the profile, and available session capacity. If the page check fails, inspect the current navigation label and heading. The script reports the failed stage without printing the raw connection error, which can contain the credential-bearing WebSocket URL. It attempts to close the tab and browser connection separately so a failed tab cleanup doesn’t prevent the second attempt.

What I built for the DevMorph experiment

I ran a single session against the public DevMorph Projects page. My code ran locally, while the cloud browser opened the site, followed the Projects link, scrolled, and returned a screenshot. I saved the image and closed the browser connection.

I also built a small local window that displayed screenshots from the remote browser during the run. It was my own screenshot-based preview. Each image showed what the browser had rendered at that moment, and the automation continued to control the browser from the script. The tutorial above demonstrates the navigation and the saved image. The video shows the preview alongside the run.

Actual DevMorph Projects page displayed in the custom screenshot-based preview during the Playwright experiment.
The original DevMorph remote browser experiment.

Commercial disclosure. GoLogin provided product access for the video. I may earn a commission if you purchase through my affiliate link or use my promo code.

Watch the full DevMorph experiment on YouTube, starting at the 3:04 demonstration.

For readers evaluating the same provider, here is my GoLogin referral link and promo code SAQIB40. Check the offer shown in Billing Plans before purchasing.

Where cloud execution earns its place

  • Regional checks. If your site behaves differently by market, use a browser with the appropriate network egress and verify the resulting locale. The machine running Node.js is only one part of that setup.
  • Bursts of parallel browser work. If browsers are saturating your CI runners, separate browser capacity may help. Give each job its own state, limit concurrency, and keep writes to shared test data isolated.
  • Browser-based monitoring and artifacts. A scheduled workflow can verify that a critical route still opens and save a screenshot for investigation. Add explicit assertions and a clear failure signal before relying on it as a monitor.

These are possible extensions. My video demonstrates one session and one workflow. For a fast feedback loop, I’d keep Playwright on my machine. For regression coverage, I’d first try browsers running on CI and check where the time goes. Playwright documents CI sharding across jobs, which can help if suite duration is the issue. Traces also make it possible to debug failures from CI without a live browser.

Cost, latency, and the data boundary

Compare the total time from job start to usable output. Separate session startup, browser work, and time spent waiting or retrying. Costs can depend on more than runtime. For example, Cloudflare documents browser hours and concurrency as separate billing dimensions for its Browser Sessions. Check your own provider’s plan, including limits and how sessions end, before increasing volume.

Give connection and navigation steps finite timeouts. Retry transient failures within a fixed budget and consider what the previous attempt may already have changed. Retrying a screenshot check and retrying a submit action have different consequences. If runs compare visuals, keep the browser version, OS, viewport, and fonts consistent where possible. Playwright’s testing best practices cover resilient locators and consistent visual test environments.

A new tab in an existing profile can share cookies and storage. Playwright browser contexts are designed to separate browsing state, and providers have their own profile and retention controls. For authenticated checks, use a dedicated test account with limited permissions. Confirm who can see session recordings and how long screenshots, logs, and profile data are retained. If the browser needs to reach private staging, first assess whether a runner inside your network is simpler than using a provider tunnel. Keep tokens out of source, recordings, and logs. Rotate a credential if it’s exposed.

Scripted automation and AI agents

In this experiment, JavaScript specifies the route, the click, and the screenshot. An AI agent can choose its next action based on what it observes. Running the browser remotely leaves the decision-making in the script. For a recurring check with a known path and outcome, explicit steps make it easy to see which operation failed.

Frequently asked questions

Do I need to install Chromium locally for this example?

No. The provider runs Chromium and the local project uses only the Playwright client library. If you later add a locally launched browser, install the matching browser binaries and any system dependencies it needs.

Can I use this CDP connection for Firefox or WebKit?

No. Playwright’s connectOverCDP() is for Chromium-based browsers. Check your provider’s separate cross-browser options or use Playwright with the appropriate engines on your runners.

Can a cloud browser open my laptop’s localhost?

Its localhost refers to its own host. To reach an app on your laptop or a private network, you need a supported tunnel or another authorized network route. A browser on an internal CI runner is often easier for private applications.

Where does Playwright save the screenshot?

In this example, it writes the file to the Node.js process’s working directory under artifacts/. If the script runs in CI, retain that directory as an artifact before the job ends.

Will remote execution make my tests faster?

It depends on the bottleneck. Extra sessions can help when runner capacity is limiting parallel tests. Short serial scripts may spend more time connecting than they save. Compare the time to a successful run, including startup and retries.

Does a full-page screenshot prove the page passed a test?

It records what rendered. To use it as a test, first assert an expected state, such as the route and heading. Add a controlled baseline and visual assertions if the workflow needs to detect visual regressions.

Choose the simplest browser setup that meets the requirement

Start with a local or CI browser, define what a successful run looks like, and capture the evidence you’ll need if it fails. Consider remote execution when you can name the constraint it solves. If you want to see how the pieces fit together, watch the complete DevMorph browser automation experiment. If your team is designing a recurring workflow around an existing site, explore DevMorph’s business automation services.

Further reading