SDK for TypeScript and Python
The SDKs wrap the Local API: they find the running app, start profiles and connect Playwright to them. Before you start, turn on the Local API and create a key for Scripts and SDK with See profiles and Start and stop profiles (see Automation overview).
The SDKs and the command line are published on npm and PyPI together with the public beta. Until then these commands do not find the packages.
TypeScript
npm install @mirage-browser/sdk playwright-core@1.63import { Mirage } from "@mirage-browser/sdk";
const mirage = new Mirage(); // reads MIRAGE_API_KEY and finds the appconst profile = await mirage.profiles.find("Shop 1");const { browser, context } = await mirage.profiles.connect(profile!.id);const page = context.pages()[0] ?? (await context.newPage());await page.goto("https://example.com");await browser.close(); // disconnects the script; the profile stays openawait mirage.profiles.stop(profile!.id); // closes the profileRun it with the key in the environment:
MIRAGE_API_KEY=mrg_… npx tsx script.ts| Method | What it does |
|---|---|
info() |
App version and what the key may do |
profiles.list({ q, sort, dir, limit, offset }) |
One page of profiles |
profiles.iterate({ q, sort, dir, limit }) |
Every profile, with for await |
profiles.get(id), profiles.find(name) |
A profile by id or exact name |
profiles.create({ name, os, coreKind, notes, proxyId, folderId, tagIds, templateId, settings }) |
Create a profile with its device OS, browser ("camoufox" for Firefox, "chromium" for Chrome), proxy, folder, tags and launch settings |
profiles.update(id, patch) |
Change name, notes, status, proxyId, folderId, the whole set of tagIds or some launch settings |
profiles.settings(id) |
Launch settings: proxyPool, timezone, locale, geolocation, startUrls, webrtc, deleteProtected and device values such as images: "off" to save traffic. In a patch, device changes only the values you pass; turning deleteProtected off is refused |
profiles.list({ scope: "trash" | "running", folderId, tagId, status }) |
Filter the list; folderId: "none" for profiles outside folders |
profiles.delete(id), profiles.restore(id) |
To the trash (30 days) and back; a running profile is not deleted |
profiles.importCookies(id, { text, mode }), profiles.exportCookies(id, { format, domains }) |
Cookies in JSON, Netscape or Base64 |
folders.list(), tags.list() |
Folders and tags with their ids |
profiles.start(id, { headless, automation }) |
Start; with automation the answer has a one-time wsEndpoint |
profiles.stop(id) |
Stop |
profiles.connect(id, { headless }) |
Start if needed and connect Playwright (Firefox or Chromium, by the profile): { browser, context, profile } |
profiles.mark(id, text) |
Put a mark with a note in the profile’s recording |
proxies.list, get, create, import, update, delete, check, changeIp |
The proxy manager |
extensions.list, get, search, add, setAutoUpdate, update, delete, install(id, profileIds), uninstall(id, profileIds), ofProfile(profileId) |
The extension library |
Python
Python 3.11 or newer. The SDK itself has no dependencies; the playwright extra installs Playwright.
pip install "mirage-browser-sdk[playwright]"from playwright.sync_api import sync_playwrightfrom mirage_sdk import Mirage
mirage = Mirage() # reads MIRAGE_API_KEY and finds the appprofile = mirage.profiles.find("Shop 1")with sync_playwright() as pw: session = mirage.profiles.connect(profile["id"], pw) page = session.context.new_page() page.goto("https://example.com") session.browser.close() # disconnects the script; the profile stays openmirage.profiles.stop(profile["id"])With async_playwright() the same call returns a coroutine: session = await mirage.profiles.connect(profile["id"], pw).
Methods mirror the TypeScript SDK in snake case: profiles.create(name, os=, folder_id=, tag_ids=), profiles.update(id, name=, notes=, status=, proxy_id=, folder_id=, tag_ids=, settings=), profiles.settings(id), profiles.import_cookies(id, text), profiles.export_cookies(id, format=), profiles.delete(id), proxies.import_list(text, ...), proxies.change_ip(id). Answers are dictionaries typed with TypedDict.
Human-like input
Playwright moves the mouse in one jump and types every key at the same pace, which anti-bot scripts notice. humanize moves the cursor along a curved path at a person’s speed (slower for far and small targets), clicks a random point near the middle of an element, holds the button briefly, and types with uneven pauses, longer after words and punctuation.
import { humanize } from "@mirage-browser/sdk";
const human = humanize(page); // one per page: it remembers where the cursor isawait human.click(page.getByRole("button", { name: "Sign in" }));await human.type("me@example.com", page.getByLabel("Email"));await human.press("Enter");await human.scroll(800);from mirage_sdk import Humanizer # AsyncHumanizer for async_playwright
human = Humanizer(page)human.click(page.get_by_role("button", name="Sign in"))human.type("me@example.com", page.get_by_label("Email"))Options: speed (2 is twice as fast), seed to repeat the same movements, and typeLimit (type_limit): text longer than this, 80 characters by default, is typed for its first 20 characters and then pasted, as a person pastes a long text. AI agents connected through MCP use the same input for every click and fill.
Read a page like a person
browse(page, human, { seconds, maxSeconds, links, acceptCookies }) stays on the page for seconds (or a random time up to maxSeconds), scrolls by varied amounts with pauses, moves the mouse, follows up to links links of the same site and, with acceptCookies, accepts cookie banners. It answers with the links it followed and how many banners and scrolls there were. Profile warm-up in the app runs the same code. In Python: browse(page, human, seconds=30, links=2, accept_cookies=True), or async_browse for async_playwright.
Connect Playwright without the SDK
Start the profile with automation and connect with Playwright’s Firefox client: Firefox profiles do not speak CDP, so connectOverCDP does not work for them. Chrome profiles take chromium.connect or CDP clients (see below).
WS=$(mirage profiles start "Shop 1")import { firefox } from "playwright-core";const browser = await firefox.connect(process.env.WS!);const context = browser.contexts()[0]!;The address works once and only for the key that asked for it. Use the existing context: Mirage does not let a script create a context with its own proxy, since the profile’s proxy and fingerprint come from the profile.
Chrome profiles: Puppeteer, Selenium and CDP
A profile on the Chrome-based core answers the start with automation.browser: "chromium" and two more addresses. profiles.connect picks Playwright’s Chromium client by itself; other tools use these:
| Field | For | Notes |
|---|---|---|
wsEndpoint |
Playwright chromium.connect |
Your Playwright must have the minor version in playwrightVersion |
cdpEndpoint |
Puppeteer browserWSEndpoint, Playwright connectOverCDP, other CDP clients |
Any version: Mirage checks the browser’s protocol version, not the client’s |
debuggerAddress |
Selenium ChromeDriver debuggerAddress |
Only when started with debugger: true; 127.0.0.1:<port> while the session lives |
import puppeteer from "puppeteer-core";
const { automation } = await mirage.profiles.start(profile.id, { automation: true });const browser = await puppeteer.connect({ browserWSEndpoint: automation!.cdpEndpoint!, defaultViewport: null });const [page] = await browser.pages();await page!.goto("https://example.com");await browser.disconnect(); // the profile stays openfrom selenium import webdriver
endpoint = mirage.profiles.start(profile["id"], automation=True, debugger=True)["automation"]options = webdriver.ChromeOptions()options.debugger_address = endpoint["debuggerAddress"]driver = webdriver.Chrome(options=options) # a ChromeDriver for Chrome 158driver.get("https://example.com")driver.service.stop() # disconnects; the profile stays openPass defaultViewport: null to Puppeteer so it keeps the profile’s window size. Full examples are in the SDK: examples/puppeteer.ts and examples/selenium_chrome.py.
What to know:
- Each start answer is for one client:
wsEndpointandcdpEndpointshare a single-use token, so the one you open first takes it. Start again for another client. - The debugger port opens only when you start with
debugger: true(debugger=Truein Python). It takes no key: any program on your computer that finds it can drive the profile while the session lives. It closes when the profile stops, 10 seconds after its last client leaves, or at once whenwsEndpointorcdpEndpointtakes the session. - Mirage keeps the profile’s fingerprint and proxy. Commands that change them (
Emulation.setUserAgentOverride,Emulation.setTimezoneOverride,Browser.setProxyand the like) and the browser target itself are refused with a message that says why; the rest of the script goes on. Because Playwright opens its CDP sessions through the browser target,newCDPSessionandnewBrowserCDPSessionare not available on Chrome profiles; Puppeteer and Selenium work without them. - AI agents through MCP work with Chrome profiles too. Their guarded click checks the element in an isolated world of the page instead of inside the browser core, so a click that ends up in a cross-site frame is reported as unconfirmed and the agent looks again.
How the SDK finds the app
baseUrl(base_url) passed tonew Mirage().- The
MIRAGE_LOCAL_API_URLenvironment variable. - The address file the app writes while the Local API is on. If the app keeps its data in a non-standard folder, set
MIRAGE_USER_DATA_DIR.
The key goes only into the Authorization header. Proxy variables such as HTTPS_PROXY are ignored for the Local API, so the key never leaves your computer.
Errors
| Error | When |
|---|---|
MirageApiError with code, status, detail, requestId |
The app refused: not_found, forbidden, unauthorized, automation_limit_reached… |
MirageError app_not_running |
Mirage is closed or the Local API is off |
MirageError no_api_key |
No key in the constructor or MIRAGE_API_KEY |
MirageError playwright_missing, playwright_version_mismatch |
Install the version from the message, or run mirage playwright install |
MirageError network, timeout |
The app did not answer |
Add requestId when you report a problem: it points to the line in the app’s log.