Automation

Connect Puppeteer, Playwright or Selenium

Step-by-step examples in Node.js and Python for driving PassKeel profiles with Puppeteer, Playwright and Selenium, with or without the SDKs.

Any tool that speaks the Chrome DevTools Protocol (CDP) or WebDriver can drive a PassKeel profile. You open the profile through the local API, connect your tool to the address it returns, do your work, and close the profile through the API so it’s saved and synced.

The profile keeps its fingerprint, proxy, cookies and extensions while your tool is connected. Attaching a tool doesn’t change what the profile presents; navigator.webdriver stays false.

Before you start

  1. Create an API key: Settings > API keys > New key, and set it as PASSKEEL_API_KEY.
  2. Find a profile’s ID: the editor’s ⋯ > Copy profile ID, or GET /v1/profiles.
  3. Install your tool without its bundled browser: PassKeel brings Keel. Use puppeteer-core and playwright-core in Node.js. In Python, pip install playwright is enough; you don’t need playwright install.

The examples use the SDKs where they save code, and plain HTTP where you might not have them. The SDKs aren’t on npm or PyPI yet; the SDKs page explains how to get them.

Playwright

Node.js (with the SDK)

// npm i playwright-core   (plus the passkeel SDK package, see /docs/sdks)
import { chromium } from 'playwright-core';
import { PassKeel } from 'passkeel';

const pk = new PassKeel(); // reads PASSKEEL_API_KEY
await pk.withProfile(process.argv[2], { headless: false }, async (opened) => {
  const browser = await chromium.connectOverCDP(opened.playwright.endpointURL);
  try {
    const context = browser.contexts()[0];   // the profile's own context: its cookies and storage
    const page = await context.newPage();
    await page.goto('https://example.com');
    console.log(await page.title());
    await page.close();
  } finally {
    await browser.close(); // only disconnects; withProfile closes the profile
  }
});

Python (with the SDK)

# pip install playwright   (plus the passkeel SDK package, see /docs/sdks)
import sys
from playwright.sync_api import sync_playwright
from passkeel import PassKeel

pk = PassKeel()
with pk.session(sys.argv[1], headless=False) as opened, sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(**opened.playwright_connect_args())
    try:
        page = browser.contexts[0].new_page()
        page.goto("https://example.com")
        print(page.title())
        page.close()
    finally:
        browser.close()  # only disconnects; the session closes the profile

Use the existing context (browser.contexts[0]). browser.newContext() creates a temporary context without the profile’s cookies and storage.

Puppeteer (Node.js)

With the SDK

// npm i puppeteer-core   (plus the passkeel SDK package, see /docs/sdks)
import puppeteer from 'puppeteer-core';
import { PassKeel } from 'passkeel';

const pk = new PassKeel();
await pk.withProfile(process.argv[2], {}, async (opened) => {
  const browser = await puppeteer.connect(opened.puppeteer); // { browserWSEndpoint, defaultViewport: null }
  const page = await browser.newPage();
  await page.goto('https://example.com');
  console.log(await page.title());
  await page.close();
  await browser.disconnect();
});

Without the SDK

// npm i puppeteer-core   (Node.js 18+ has fetch built in)
import puppeteer from 'puppeteer-core';

const API = 'http://127.0.0.1:50325';
const headers = { 'X-Api-Key': process.env.PASSKEEL_API_KEY, 'Content-Type': 'application/json' };
const id = process.argv[2];

const res = await fetch(`${API}/v1/profiles/${id}/open`, { method: 'POST', headers, body: '{}' });
if (!res.ok) throw new Error(`open failed: ${res.status} ${await res.text()}`);
const { automation } = await res.json();

const browser = await puppeteer.connect({ browserWSEndpoint: automation.browserWSEndpoint, defaultViewport: null });
try {
  const page = await browser.newPage();
  await page.goto('https://example.com');
  console.log(await page.title());
} finally {
  await browser.disconnect();
  await fetch(`${API}/v1/profiles/${id}/close`, { method: 'POST', headers });
}

Keep defaultViewport: null: otherwise Puppeteer forces an 800×600 viewport that doesn’t match the profile’s window and screen.

Selenium

PassKeel runs the chromedriver that matches the profile’s browser version for you. Point Selenium’s Remote WebDriver at the profile’s webDriverUrl; options that would launch a browser are ignored.

Python

# pip install selenium   (plus the passkeel SDK package, see /docs/sdks)
import sys
from selenium import webdriver
from passkeel import PassKeel

pk = PassKeel()
with pk.session(sys.argv[1]) as opened:
    driver = webdriver.Remote(command_executor=opened.selenium_remote_url(),
                              options=webdriver.ChromeOptions())
    try:
        driver.switch_to.new_window("tab")
        driver.get("https://example.com")
        print(driver.title)
    finally:
        driver.quit()  # ends the WebDriver session; the session closes the profile

Node.js

// npm i selenium-webdriver   (plus the passkeel SDK package, see /docs/sdks)
import { Builder, Browser } from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome.js';
import { PassKeel } from 'passkeel';

const pk = new PassKeel();
await pk.withProfile(process.argv[2], {}, async (opened) => {
  const driver = await new Builder()
    .usingServer(opened.selenium.serverUrl)
    .forBrowser(Browser.CHROME)
    .setChromeOptions(new chrome.Options())
    .build();
  try {
    await driver.switchTo().newWindow('tab');
    await driver.get('https://example.com');
    console.log(await driver.getTitle());
  } finally {
    await driver.quit();
  }
});

Python without the SDK

import os, sys, requests
from selenium import webdriver

API = "http://127.0.0.1:50325"
H = {"X-Api-Key": os.environ["PASSKEEL_API_KEY"]}
pid = sys.argv[1]

auto = requests.post(f"{API}/v1/profiles/{pid}/open", json={}, headers=H).json()["automation"]
driver = webdriver.Remote(command_executor=auto["webDriverUrl"], options=webdriver.ChromeOptions())
try:
    driver.get("https://example.com")
    print(driver.title)
finally:
    driver.quit()
    requests.post(f"{API}/v1/profiles/{pid}/close", headers=H)

Many profiles

Run profiles in parallel by opening several and connecting to each. Keep these in mind:

  • Memory: each open profile is a full browser; plan for roughly 600 MB each. GET /v1/resources reports what each one uses.
  • Rate limit: 3,000 API requests a minute per key; the browser traffic itself doesn’t count.
  • Always close profiles through POST /v1/profiles/{id}/close (the SDK helpers do this, even after an error). Closing the browser from your tool (browser.close() on a launched browser, Browser.close over CDP) isn’t allowed: it would skip saving and syncing.
# Python: run a task on several profiles, four at a time
from concurrent.futures import ThreadPoolExecutor
from passkeel import PassKeel
from playwright.sync_api import sync_playwright

pk = PassKeel()

def task(profile_id):
    with pk.session(profile_id, headless=True) as s, sync_playwright() as p:
        b = p.chromium.connect_over_cdp(**s.playwright_connect_args())
        page = b.contexts[0].new_page()
        page.goto("https://example.com/account")
        result = page.title()
        b.close()
        return profile_id, result

ids = pk.list_profiles(tag="daily-check", view="ids")["ids"]   # {"ids": [...]}
with ThreadPoolExecutor(max_workers=4) as ex:
    for pid, title in ex.map(task, ids):
        print(pid, title)

view=ids returns just the matching IDs ({"ids": [...]}); view=summary and view=full return profile objects. Query parameters are keyword arguments in Python (tag=, status=, groupId=) and an options object in Node.js. See List and search profiles.

Headless

headless: true opens the profile without a window. Keel applies every setting as it does with a window, so pages see the same identity. Use it for scheduled jobs on a computer you’re not watching; use a window while you develop a script.

Troubleshooting

Problem Cause and fix
PassKeelConnectionError / connection refused PassKeel’s background service isn’t running, or it uses another port. Start PassKeel; check the port in Settings.
401 Missing or wrong API key.
403 with a locked profile Send the account PIN in the open request (pin).
409 already_open The profile is already open. Use GET /v1/profiles/{id}/automation to connect to it.
409 sync_locked It’s open on another computer. See Hand-over.
No automation connection for a shared profile You need the Export data and automate permission on it.
A CDP command answers “method not found” It’s one of the commands PassKeel blocks (such as Browser.close). Use the API instead.
Pages load without the profile’s cookies You created a new context; use browser.contexts[0].