TutorialWindows and Mac

Playwright and Puppeteer: connect to a signed-in profile through CDP

A guide by Mantis Browser: examples use our own app.

Reuse a Chromium profile’s context, obtain its correct endpoint, and distinguish disconnecting your script from closing the browser.

2 min readLeer en español

Start with a test profile#

CDP lets a tool connect to a running Chromium instance. Its existing context contains the profile’s storage: creating another context in your script is not the same as using the session you prepared. Start on your own test page or an example page, without purchases or production changes.

In Mantis, API and CDP require Pro or Max. Keep the app open and signed in on the script’s PC. Use GET /v1/perfiles to obtain the ID and POST /v1/perfiles/:id/start to start the profile; use automation.wsEndpoint from the response instead of rebuilding it from a port.

Example using Playwright and the Mantis API#

Install requests and playwright in your Python environment. Replace the example ID with a test profile’s ID. The script opens an example.com tab, prints its title and requests profile shutdown afterward, even if navigation fails.

Python: existing context
import requests
from playwright.sync_api import sync_playwright

API = "http://127.0.0.1:3848/v1"
PROFILE_ID = "REPLACE_WITH_PROFILE_ID"

def request(method, path):
    result = requests.request(method, API + path, timeout=120)
    result.raise_for_status()
    return result

started = request("POST", f"/perfiles/{PROFILE_ID}/start").json()
try:
    with sync_playwright() as p:
        browser = p.chromium.connect_over_cdp(started["automation"]["wsEndpoint"])
        context = browser.contexts[0]
        page = context.new_page()
        page.goto("https://example.com")
        print(page.title())
        page.close()
finally:
    request("POST", f"/perfiles/{PROFILE_ID}/stop")

Puppeteer: disconnecting does not stop the profile#

Node.js: use the endpoint returned by start
import puppeteer from "puppeteer-core";

// Set WS_ENDPOINT to automation.wsEndpoint from the start response.
const endpoint = process.env.WS_ENDPOINT;
if (!endpoint) throw new Error("WS_ENDPOINT is required");
const browser = await puppeteer.connect({ browserWSEndpoint: endpoint });
try {
  const page = await browser.newPage();
  await page.goto("https://example.com");
  console.log(await page.title());
  await page.close();
} finally {
  browser.disconnect();
}

Install puppeteer-core. This second example only disconnects Puppeteer; call /stop afterward if you want to close the profile. The Puppeteer reference documents connect. Playwright notes CDP limitations compared with its own protocol.

Three errors to isolate#

  • Connection refused: confirm the profile is still open and you are using that launch’s endpoint.
  • Missing session: check the reused context and whether the site revoked authentication.
  • Interfering tasks: avoid two scripts modifying the same profile simultaneously; limit concurrency for your PC.

These examples describe the integration, not compatibility with every website or version. The automation manual covers the full workflow. Do not publish token-bearing endpoints or expose the local API to the Internet.

Put the guide into practice with Mantis

If you need to organize projects on Windows or Mac, try Mantis with 5 profiles on 1 computer, with no card or expiry. Advanced features such as API/CDP, bulk creation and backups depend on your plan; check the limits before buying.

If you would rather stick with what you already use, keep the organization part: it applies just the same.

Continue in the manual

Automation with Playwright and PuppeteerLocal API referenceCreate, edit and start profiles

Cookies and storage

Necessary: used when you choose a language, sign in or buy. Disabling them affects those features; you can clear them through your browser.

Optional first-party statistics: daily totals by page and campaign, retained for 180 days. No stored IP addresses or visitor identifiers (if you arrive from an ad, a hashed code of your connection for 7 days to attribute the signup in the app). These first-party statistics are not sent to Google. The campaign is remembered only in this tab if you accept. You can reject or withdraw your choice here; website features remain available.

Google receives technical data (IP address, browser and ad click), verified signups and confirmed purchases (order reference, amount and currency). We send no emails, passwords or browser profile data. Ad personalization requires the additional option below. We use no enhanced conversions. Its tag loads only if you accept this option.

Allows ads on Google, YouTube, Facebook and Instagram based on your website visits and interactions. Includes the Google measurement above and the Meta pixel for visits, downloads, verified signups and confirmed purchases. Meta receives IP address, browser, advertising identifiers and website events; never emails, passwords or browser profile data. You can withdraw permission here.

Only with this option, TikTok receives visits, downloads, verified signups and confirmed purchases through its pixel and Events API. Includes IP address, browser, ad identifiers, order reference, amount and currency; never emails, passwords or browser profile data. This permission is independent of Google and Meta and can be withdrawn here.

Read the full policy