Skip to content

Playwright, Puppeteer, Selenium

The approach is the same everywhere: launch the profile through the local API, get the CDP address, and connect to the already running browser. Geksy launches the browser, not your script; otherwise you get no fingerprint, no proxy, and no sync.

Scripts read the local API port and token from %LOCALAPPDATA%\Geksy\agent.json. Get the workspace and profile IDs (WS, PROFILE) in the web app or through the cloud API.

Playwright and Puppeteer connect to the permanent profile address with a token (POST /api/v1/cdp-tokens): through it, the app hides signs of a connected automation client from the page. Selenium connects to the direct address from the start response, since ChromeDriver can’t send a token. More on the permanent address, recipes for Patchright, browser MCP servers, browser-use, Stagehand, and the tested versions are in Connect your browser code.

import json, os, requests
from playwright.sync_api import sync_playwright
cfg = json.load(open(os.path.expandvars(r"%LOCALAPPDATA%\Geksy\agent.json")))
API = f"http://127.0.0.1:{cfg['port']}/api/v1"
H = {"Authorization": f"Bearer {cfg['token']}"}
WS, PROFILE = "1b7e…", "8f0c…"
requests.post(f"{API}/profiles/{PROFILE}/start", json={"workspace_id": WS, "headless": False}, headers=H)
T = requests.post(f"{API}/cdp-tokens", json={"workspace_id": WS, "profile_id": PROFILE}, headers=H).json()
with sync_playwright() as pw:
browser = pw.chromium.connect_over_cdp(T["http_endpoint"], headers=T["headers"])
ctx = browser.contexts[0]
page = ctx.pages[0] if ctx.pages else ctx.new_page()
page.goto("https://example.com")
print(page.title())
browser.close() # disconnect; the profile itself keeps running
requests.post(f"{API}/profiles/{PROFILE}/stop", json={"workspace_id": WS}, headers=H) # close; data goes to the cloud

With the Python SDK, it’s shorter: Agent().start(WS, PROFILE) launches the profile, and Agent().cdp_token(WS, PROFILE) returns the permanent address and headers.

import { readFileSync } from "node:fs";
import puppeteer from "puppeteer-core";
const cfg = JSON.parse(readFileSync(`${process.env.LOCALAPPDATA}\\Geksy\\agent.json`, "utf8"));
const API = `http://127.0.0.1:${cfg.port}/api/v1`;
const H = { Authorization: `Bearer ${cfg.token}`, "Content-Type": "application/json" };
const WS = "1b7e…", PROFILE = "8f0c…";
await fetch(`${API}/profiles/${PROFILE}/start`, {
method: "POST", headers: H, body: JSON.stringify({ workspace_id: WS, headless: false }),
});
const T = await (await fetch(`${API}/cdp-tokens`, {
method: "POST", headers: H, body: JSON.stringify({ workspace_id: WS, profile_id: PROFILE }),
})).json();
const browser = await puppeteer.connect({ browserWSEndpoint: T.ws_endpoint, headers: T.headers, defaultViewport: null });
const [page] = await browser.pages();
await page.goto("https://example.com");
console.log(await page.title());
await browser.disconnect();

Install puppeteer-core, not puppeteer: the browser is already there, so you don’t need to download another Chromium. defaultViewport: null keeps the real window size, so it matches the fingerprint.

Selenium connects to the browser at the host:port debugging address, which is cdp_http without http://.

import json, os, requests
from selenium import webdriver
cfg = json.load(open(os.path.expandvars(r"%LOCALAPPDATA%\Geksy\agent.json")))
API = f"http://127.0.0.1:{cfg['port']}/api/v1"
H = {"Authorization": f"Bearer {cfg['token']}"}
WS, PROFILE = "1b7e…", "8f0c…"
p = requests.post(f"{API}/profiles/{PROFILE}/start", json={"workspace_id": WS, "headless": False}, headers=H).json()
opts = webdriver.ChromeOptions()
opts.debugger_address = p["cdp_http"].removeprefix("http://") # "127.0.0.1:53412"
driver = webdriver.Chrome(options=opts)
driver.get("https://example.com")
print(driver.title)
driver.service.stop() # disconnect the driver; driver.quit() would close the browser windows

The Geksy engine doesn’t turn on the debugging mode in pages that sites use to spot automation. Because of that:

  • Page console events (page.on("console") in Playwright and Puppeteer) don’t arrive. Read the page messages yourself: capture console with a script and collect what has piled up, for example page.add_init_script("window.__log=[];['log','warn','error'].forEach(k=>{const f=console[k];console[k]=(...a)=>{window.__log.push([k,...a].join(' '));f(...a)}})") and then page.evaluate("window.__log.splice(0)"). Or use the local API eval action (an isolated world: page variables aren’t visible to it).
  • exposeBinding and exposeFunction in Playwright don’t work: the page can’t call a function of your script. Instead, poll: the page puts data into a variable or the DOM, and the script reads it with evaluate on a timer; or use local API actions (wait_for, extract). Puppeteer exposeFunction and Patchright exposeBinding work.
  • Downloads over CDP are saved on the computer where the browser runs: the script gets the event and the file name, and the file lands in the profile’s downloads folder on that computer.
  • Selenium connects to the direct debugging address (cdp_http); ChromeDriver can’t connect through the permanent token address because it can’t send the token. Use the ChromeDriver with the same major version as the engine.

Tested versions are in Connect your browser code.

Each profile is a separate browser process with its own CDP addresses. Launch them one by one through the local API and connect to each in its own thread or task. How many profiles your PC can handle depends mostly on memory.

  • Don’t override the User-Agent, time zone, language, or window size with Playwright or Puppeteer: the fingerprint already handles this, and manual overrides create mismatches.
  • Use "headless": true for background tasks.
  • Close the profile with a stop call; that way the data is guaranteed to reach the cloud.