NinjaSurfer Docs / JavaScript SDK ← Back to the site
Docs · JavaScript SDK

JavaScript SDK

The SDK is JavaScript only; there is no Python package. Install the signed SDK tarball with its peers playwright-core (the version its package.json names) and ws 8+. It is not on public npm. The installed package's .d.ts files are the reference for exact signatures. The signed standalone CLI and the MCP server run the same SDK code.

Entrypoints

The root NinjaSurfer launches Chromium; NinjaSurferClient talks to the account API. Each has its own option type. The index and ninjasurfer/client export the same account-client constructor.

Public operations by area

Engine feature inspection uses engineSupportsSwitch(executable, name) and engineSwitches(executable), both from the signed start contract. engineSwitches returns null for an unknown executable. catalogVersionFor({ executable, version }) resolves the shipped catalog from the selected signed engine; version is optional.

A first run

javascript
import { SDK_VERSION, loadPersonaCatalog } from "ninjasurfer";

const catalog = loadPersonaCatalog();
console.log({ sdk: SDK_VERSION, personas: catalog.entries.length });

Save it as catalog.mjs beside node_modules and run node catalog.mjs. It needs no account and downloads nothing.

MCP profile references

MCP uses the profile_* tool family with explicit scope: "local" | "workspace" for profile operations. Local SDK ids and workspace card ids belong to different stores. profile_create groups settings, metadata and picks; profile_update groups changes and metadata. These transport arguments do not change the SDK's typed function contracts. An embedded host may supply StartMcpOptions.profileCatalog: McpProfileCatalog; its root must match the service, and a supplied catalog's error is propagated rather than selecting the default stores.

Launching profiles

A launch needs the engine and the components the profile's persona uses (fonts, network helpers), an account that may run it, and the profile's grant. Desktop prepares them; the SDK's runtime preparation does the same from code. Chromium and WebKit launch differently: CDP applies to Chromium, and WebKit uses its own Playwright transport. There is no Windows WebKit engine. Every download goes through the SDK's asset manager (see installation).

The CLI fetch [--browser-version X] prepares the SDK runtime plan (the engine and each persona OS's font sets) through one prepareRuntime call, then prints the engine path. Runtime preparation verifies and repairs missing or damaged resources. path --download requests only the engine through the same planner.

Updates

checkForUpdates() reports what is newer (SDK, engine, components, font sets); update(items) installs the requested updates. A requested create/start can update an already installed outdated engine and retry once; creating a profile does not fetch its first engine. One engine serves every profile: a profile is not bound to an engine version.

The account client

Credential lifetime

Create one credential context for each embedded service or account session. Its environment and successful key-file reads belong to that context. Asynchronous work started inside the scope retains it, including background profile preparation. Explicit client options still take precedence when constructing that client.

javascript
import { createSdkCredentials, runWithSdkCredentials, NinjaSurferClient } from "ninjasurfer";

const credentials = createSdkCredentials({ env: process.env });
await runWithSdkCredentials(credentials, async () => {
  const account = new NinjaSurferClient();
  await account.verify();
});

There is no process-wide API key. Construct a new context to change accounts; existing clients retain the configuration captured when they were constructed.

(a) The client and its namespaces

new NinjaSurferClient({ apiKey, baseUrl }) does no network on construction. verify() checks the key and caches the account, plan and quotas (GET /v1/me) on me. Namespaces:

API-key routes send the key as a Bearer token. The session routes (POST /v1/auth/{login,logout,signup}, and OAuth) return a session token; there is no refresh route, so a session is renewed by logging in again. /v1/runs/:runId/renew renews a sealed launch token, not a session.

(b) The error envelope

The error body is { "error": { "code", "message", "details"?, "validation_error"? } }. The SDK raises it as one NinjaSurferError with the HTTP status and the code; with no code, the status decides it. A flat { "error": "<reason>" } body from an auth route maps no_token/bad_token on a 401 to AUTH_REQUIRED, and any other reason to the status default. errorCode(e) and ERROR_CODES (both exported) name every code.

(c) Installs and the launch gate

client.installs is the device install this SDK copy represents. Run leases and sealed launch tokens are bound to it (/v1/installs).

See also

Profiles, personas, MCP and agents, system components, the package's own README.md.