Automating JustBrowser From Node.js: A TypeScript Quickstart
A scraping script can throw ECONNREFUSED even when profiles launch fine from the GUI. The script simply can't reach the API.
The usual cause is a hardcoded port: the script expects one port while the API listens on another.
Dull bug. Easy to lose an evening to. Port mix-ups are also the first thing to rule out whenever a local automation script stops talking to its app.
Playwright and Puppeteer both have first-class Node.js libraries. This post gives you a typed Node.js client for the JustBrowser REST API, plus Playwright integration via connectOverCDP. If you want a Python version, our Playwright and Puppeteer automation guide covers the same ideas.
By the end, you'll have working TypeScript that launches profiles, grabs the CDP endpoint, attaches Playwright, runs automation, and shuts down cleanly.
Prerequisites
Before we start:
- JustBrowser installed and running on Windows x64 or macOS (Apple Silicon). The API is local: it's bound to
127.0.0.1, port36542by default and configurable in the app. There is no hosted API and nothing to call atapi.justbrowser.app. - An active subscription or trial — API access needs one. The plan is $9.99/month or $99.99/year with unlimited profiles, after a 7-day free trial that requires a card. Team seats don't get API access.
- An API token — generate it on the AI page in the app and send it as a Bearer token.
- Node.js 18+ with TypeScript configured — we'll use native fetch (no axios needed)
- Playwright installed —
npm install playwrightornpm install playwright-coreif you don't need bundled browsers - At least one Chrome profile created in the GUI — you'll need its ID, which
GET /profileswill list for you
Don't have a profile? Open JustBrowser, click New Profile, accept defaults, save.
Step 1: Define TypeScript Types
First, type the API responses. This saves you from runtime surprises when a property name is misremembered:
// types.ts
interface ProfileSummary {
id: string;
name: string;
}
interface StartResult {
cdp_url: string; // ws://127.0.0.1:PORT/devtools/browser/<guid>
}
Responses and errors are enveloped, so real code should unwrap data and branch on error.code, never on the message text. Keep the types minimal and add fields as you actually use them. The full responses carry more than this, and the OpenAPI spec at justbrowser.app/docs lists all of it.
Step 2: Set Up the Client and Check Connectivity
Before anything fancy, make sure the API is reachable. Obvious, yes, and still the actual problem more often than any code bug:
const API_BASE = 'http://127.0.0.1:36542/api/v1';
const TOKEN = process.env.JUSTBROWSER_TOKEN!; // from the AI page in the app
async function api<T>(path: string, init: RequestInit = {}): Promise<T> {
const response = await fetch(`${API_BASE}${path}`, {
...init,
headers: {
Authorization: `Bearer ${TOKEN}`,
...(init.body ? { 'Content-Type': 'application/json' } : {}),
...init.headers,
},
});
const body: any = await response.json();
if (!response.ok) {
throw new Error(`${body.error?.code}: ${body.error?.message}`);
}
return body.data as T;
}
If you get TypeError: fetch failed or ECONNREFUSED, JustBrowser isn't running or the port is different. Check the app. This trips people up more than anything else.
Step 3: List Available Profiles
Let's see what profiles exist:
const { profiles } = await api<{ profiles: ProfileSummary[] }>('/profiles');
for (const profile of profiles) {
console.log(`ID: ${profile.id} | Name: ${profile.name}`);
}
Copy the ID of the profile you want to drive. That also doubles as your connectivity check: if the list comes back, the token and port are right.
Step 4: Start a Profile
Starting a Chrome profile launches an actual Chromium process with your configured fingerprint. It takes a moment, so don't expect an instant return:
const PROFILE_ID = 'your-profile-id'; // from GET /profiles
async function startProfile(profileId: string, headless = false): Promise<StartResult> {
return api<StartResult>(`/profiles/${profileId}/start`, {
method: 'POST',
body: JSON.stringify({ headless }),
});
}
const { cdp_url } = await startProfile(PROFILE_ID);
console.log(`CDP endpoint: ${cdp_url}`);
One gotcha, and it's the single most common surprise: POST /profiles/{id}/start starts headless unless the body says {"headless": false}. Send the JSON body with the right Content-Type, as above, whenever you expect a visible window.
A headless session has no real window, so its screen and viewport follow headless defaults. For anything where window size and screen geometry matter, run headed. That's the right default for most multi-account work, even if it costs you a window on screen.
Step 5: Attach Playwright
This is the payoff:
import { chromium } from 'playwright';
const browser = await chromium.connectOverCDP(cdp_url);
const context = browser.contexts()[0]; // the profile's own context
const page = context.pages()[0] ?? (await context.newPage());
await page.goto('https://browserleaks.com/canvas');
console.log(`Page title: ${await page.title()}`);
Use contexts()[0]. Never call browser.newContext(): that creates an incognito context outside the profile, and you lose the identity you started it for.
Playwright drives the browser, but the engine itself applies the profile's identity parameters in native C++, so the canvas test on BrowserLeaks shows the profile's canvas fingerprint, not your machine's.
Puppeteer users get the same result:
import puppeteer from 'puppeteer-core';
const browser = await puppeteer.connect({ browserWSEndpoint: cdp_url });
const pages = await browser.pages();
const page = pages[0] ?? (await browser.newPage());
Same endpoint, different API. For most tasks Playwright's auto-waiting and locators read better, in our view, but Puppeteer has a bigger pile of existing scripts, so pick what fits your team.
Step 6: Clean Up
Don't leave browsers running. Memory disappears fast with a pile of Chromium instances open:
async function stopProfile(profileId: string): Promise<void> {
await api(`/profiles/${profileId}/stop`, { method: 'POST' });
}
await browser.close(); // only disconnects Playwright
await stopProfile(PROFILE_ID); // actually ends the session
console.log('Profile stopped');
browser.close() only disconnects. The profile keeps running until you call /stop. The profile data (fingerprint config, cookies, history) persists, so the next start gives you a fresh process with the same identity. Profile equals persistent data; browser instance equals ephemeral process.
Complete Working Example
Everything tied together in one runnable script:
// justbrowser-client.ts
import { chromium } from 'playwright';
const API_BASE = 'http://127.0.0.1:36542/api/v1';
const TOKEN = process.env.JUSTBROWSER_TOKEN!;
const PROFILE_ID = 'your-profile-id';
async function api<T>(path: string, init: RequestInit = {}): Promise<T> {
const response = await fetch(`${API_BASE}${path}`, {
...init,
headers: {
Authorization: `Bearer ${TOKEN}`,
...(init.body ? { 'Content-Type': 'application/json' } : {}),
...init.headers,
},
});
const body: any = await response.json();
if (!response.ok) throw new Error(`${body.error?.code}: ${body.error?.message}`);
return body.data as T;
}
async function main() {
console.log('Starting profile...');
const { cdp_url } = await api<{ cdp_url: string }>(
`/profiles/${PROFILE_ID}/start`,
{ method: 'POST', body: JSON.stringify({ headless: false }) }
);
const browser = await chromium.connectOverCDP(cdp_url);
const context = browser.contexts()[0];
const page = context.pages()[0] ?? (await context.newPage());
await page.goto('https://browserleaks.com/canvas');
console.log('Check the canvas fingerprint in the browser window');
// Wait for a human to inspect
await new Promise(resolve => setTimeout(resolve, 10000));
await browser.close();
await api(`/profiles/${PROFILE_ID}/stop`, { method: 'POST' });
console.log('Done.');
}
main().catch(console.error);
Run with npx ts-node justbrowser-client.ts (or compile and run with Node). Your profile opens, navigates to a fingerprint checker, waits 10 seconds, then closes.
Common Errors and How to Fix Them
TypeError: fetch failed or ECONNREFUSED
Cause: JustBrowser isn't running, or the port is wrong.
Fix: Start JustBrowser. Check the app for the actual port. The default is 36542, but if you've changed it (or something else grabbed that port), update API_BASE.
VALIDATION_ERROR
Cause: The request body didn't match what the endpoint expects.
Fix: Read error.details: it's an array of issues, one per problem. Branch on error.code, never on the message string.
Profile not found
Cause: Typo in the profile ID, or the profile was deleted.
Fix: Call GET /profiles to list all profiles and copy the exact ID.
Start fails because the profile is already running
Cause: The profile is active from a previous session, maybe one that crashed before cleanup.
Fix: Stop it first with POST /profiles/{id}/stop, then start again.
Playwright connects but page actions fail
Cause: The browser may still be initialising right after start.
Fix: Add a short delay before connecting:
const { cdp_url } = await startProfile(PROFILE_ID);
await new Promise(r => setTimeout(r, 2000)); // short buffer
const browser = await chromium.connectOverCDP(cdp_url);
A sleep() feels gross, and a cleaner option is retrying the connect in a short loop. Same outcome, more code.
The CDP endpoint works once then throws
Cause: The browser closed (intentionally or crashed) and the endpoint is stale.
Fix: Endpoints are per-session. If the browser dies, start the profile again for a fresh cdp_url. For long-running automation, add reconnection logic that catches connection errors and restarts.
Next Steps
From here:
- Profile pools for concurrency: when running several profiles, build a pool manager that tracks which are in use. The Playwright automation guide covers pool patterns.
- Proxy configuration: each profile can have its own proxy. Keep the proxy's location consistent with the profile's timezone and locale, because a "Chicago laptop" shouldn't route through Frankfurt.
- Checking your setup: before production, open a page like BrowserLeaks in a profile to see which settings it presents.
- Bulk creation: up to 100 profiles per call from a naming pattern. There's no CSV importer.
If you're doing ad verification, pair your setup with ClickzProtect to watch your own campaigns for click fraud. For tracking conversions without cookies, JustAnalytics offers cookieless analytics.
The full API reference is at justbrowser.app/docs, with an anchor per endpoint and the raw OpenAPI spec at /docs/openapi.json. There's one plan, and it starts with a 7-day trial that requires a card.
Start simple: fetch and a few endpoints. Once that feels solid, add Playwright.
Frequently Asked Questions
Can I use the JustBrowser API without Playwright or Puppeteer?
Yes. The REST API is standalone — launch profiles, list them, grab CDP endpoints, stop sessions — all via HTTP. Playwright, Puppeteer, and Selenium are optional add-ons that connect to the CDP endpoint. You could manage profiles entirely from fetch calls or even curl if that's your preference.
Why TypeScript instead of plain JavaScript?
Type safety catches API response shape errors at compile time. When the start endpoint returns cdp_url, a typed interface makes sure you're reading that property and not a misremembered one. You can skip types if you want — the runtime doesn't care — but debugging API integration bugs without types is painful.
Is the REST API reachable from another machine?
No. It's bound to 127.0.0.1, so your script has to run on the same machine as the JustBrowser app. There is no hosted API endpoint.
Do I need to install Chrome or Chromium separately?
No. JustBrowser includes its own Chromium build with native fingerprint patches. The REST API controls that built-in engine. Playwright's chromium.connectOverCDP connects to it — you're not launching Playwright's bundled browser, you're attaching to JustBrowser's already-running instance.
Try JustBrowser
A multi-account browser for teams, built on a custom Chromium engine — not extension-based. Real C++ engine patches at the canvas / WebGL / audio / font / screen layer, so 40+ identity parameters are genuine, not faked. REST API for Playwright, Puppeteer, Selenium. 7-day free trial, card required — then $9.99/month or $99.99/year, unlimited profiles, free team seats.
Get started → · How it differs from Multilogin / GoLogin / AdsPower
Ready to manage multiple accounts?
Seven days free, then $9.99/month — one plan, everything included.