Playwright setup

Attach Playwright to a persistent profile.

Start an AliasMode browser through the Local API, read its CDP WebSocket endpoint, and connect Playwright without creating a separate temporary browser context.

Tested 2026-08-10

Prerequisites

Install AliasMode and CloakBrowser, create a profile, enable the Local API, and add Playwright to the automation project. The profile must be available on the same computer as the script.

  • AliasMode desktop app running
  • Local API available at 127.0.0.1:50400
  • A valid profile ID
  • Playwright installed in the Node.js project

Start and connect

Call the browser start route with the profile ID. Read response.data.ws.puppeteer, then pass it to chromium.connectOverCDP. The attached browser uses the profile’s persistent data, proxy, cookies, and active session.

import { chromium } from 'playwright';

const origin = 'http://127.0.0.1:50400';
// Find this ID with GET /api/v1/user/list.
const profileId = process.env.ALIASMODE_PROFILE_ID;
if (!profileId) throw new Error('Set ALIASMODE_PROFILE_ID');

const startUrl = new URL('/api/v1/browser/start', origin);
startUrl.searchParams.set('user_id', profileId);

let browser;
let started = false;
try {
  const startResponse = await fetch(startUrl);
  if (!startResponse.ok) {
    throw new Error(`AliasMode returned HTTP ${startResponse.status}`);
  }

  const payload = await startResponse.json();
  const cdpUrl = payload?.data?.ws?.puppeteer;
  if (payload?.code !== 0 || typeof cdpUrl !== 'string') {
    throw new Error(payload?.msg || 'AliasMode did not return a CDP URL');
  }

  started = true;
  browser = await chromium.connectOverCDP(cdpUrl);
  // Run automation with the connected browser.
} finally {
  try {
    await browser?.close();
  } finally {
    if (started) {
      const stopUrl = new URL('/api/v1/browser/stop', origin);
      stopUrl.searchParams.set('user_id', profileId);
      await fetch(stopUrl);
    }
  }
}

Close cleanly

The example uses finally so it disconnects Playwright and stops the profile after success or failure. Keep one automation owner per active profile to avoid overlapping actions.