Playwright scripts on NinjaSurfer
An existing Playwright script moves to NinjaSurfer by changing its import and its launch. ninjasurfer/playwright has
the shape of playwright / playwright-core: its chromium launches NinjaSurfer's engine with a persona, and returns
the standard Playwright BrowserContext, so the rest of the script (newPage, locators, close) stays as it is.
NinjaSurfer's release engines start only from a profile of your NinjaSurfer account. So you need an API key
(NINJASURFER_API_KEY) and a profile made with it:
ninjasurfer profile create shop-1 --scope local --persona-os mac
// before
import { chromium, devices } from "playwright";
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext();
// after
import { chromium, devices } from "ninjasurfer/playwright";
const context = await chromium.launchPersistentContext("", { profile: "shop-1", headless: true });
const page = await context.newPage();
await page.goto("https://example.com");
await context.close();On a release engine, chromium.launch(), chromium.launchPersistentContext(dir) and a profile that isn't linked to
your account are refused with TOKEN_MISSING, and the error names the call above. They run only on an engine that
doesn't require a profile token (a build you name with executablePath).
The SDK and its peer playwright-core (1.64.1) are installed as in the JavaScript SDK.
What chromium does
| Call | On NinjaSurfer |
|---|---|
chromium.launch(options) |
Refused on a release engine (see above). Otherwise starts NinjaSurfer's engine with a persona: the same as NinjaSurfer(options) from ninjasurfer. Playwright's launch options (headless, args, proxy, slowMo, timeout, env, …) pass as they are; a proxy server without a scheme (host:3128) is http, as in Playwright. NinjaSurfer's own go beside them: personaSeed (a stable persona), timezone, locale, graphics and the others of NinjaSurferOptions. |
chromium.launchPersistentContext(dir, options) |
Refused on a release engine (see above). Otherwise a persistent context in dir. The directory keeps one persona: without personaSeed, a random one is drawn on its first launch and kept in the directory (.ninjasurfer-persona), so the next run is the same device with the same state. "" gives a temporary directory, removed when the context closes, as in Playwright. |
chromium.launchPersistentContext("", { profile }) |
Opens a NinjaSurfer profile (by id or name) from the profile store, with its persona, proxy, fonts and settings. Pass "": the profile keeps its own data. On a release engine this is the way to start, with a profile of your account and your API key. |
chromium.connectOverCDP(endpoint) / chromium.connect(wsEndpoint) |
Playwright's own: attach to a profile that is already running, at its DevTools endpoint (ninjasurfer start --json prints cdpEndpoint; MCP's browser_cdp_endpoint gives it to an agent). |
chromium.name() |
"chromium". |
devices, errors, selectors and request are playwright-core's own. A device descriptor still emulates in the
context only (viewport, user agent); the persona is the device sites see underneath.
Not supported, said at the call rather than ignored:
channel("chrome","msedge", …): NinjaSurfer always runs its own engine.executablePathmay name another NinjaSurfer build.chromium.executablePath(): the engine is resolved at launch (ninjasurfer fetchinstalls it).firefoxandwebkitare not exported fromninjasurfer/playwright: they would be plain Playwright browsers. The WebKit persona engine islaunchWebKit/launchWebKitPersistentfromninjasurfer.
A persona per directory, a persona per profile
Playwright's persistent context is "the same browser next time". On NinjaSurfer the device a site sees is part of that.
On an engine that doesn't require a profile token, a directory always launches with the persona drawn on its first run, kept in the directory itself. So the same path on
two machines (/tmp/profile, /app/data in a container) is two different devices, and a directory you move or copy
keeps its device. To choose the persona, pass personaSeed; to keep a proxy, a time zone and the rest with it, use a
NinjaSurfer profile (ninjasurfer profile create, then launchPersistentContext("", { profile })).