Appearance
Usage
All examples assume the Nstbrowser client (or Docker container) is running on localhost:8848. Replace your_api_key and your_profile_id with real values from the dashboard.
Node.js SDK: Start and Stop a Browser Profile
javascript
import { NstBrowserV2 } from 'nstbrowser-sdk-node';
const client = new NstBrowserV2('your_api_key', {
timeout: 60000,
apiAddress: 'http://localhost:8848/api/v2'
});
const profileId = 'your_profile_id';
// Launch the browser profile
const startResponse = await client.browsers().startBrowser({ profileId });
console.log('Browser started:', startResponse);
// Close the browser profile
const stopResponse = await client.browsers().stopBrowser({ profileId });
console.log('Browser stopped:', stopResponse);Node.js SDK + Puppeteer: Navigate via CDP
Connect Puppeteer to a running Nstbrowser profile through the CDP WebSocket endpoint:
javascript
import { NstBrowserV2 } from 'nstbrowser-sdk-node';
import puppeteer from 'puppeteer-core';
const client = new NstBrowserV2('your_api_key');
// Launch and get the CDP WebSocket URL
const cdpResponse = await client.cdpEndpoints().connectBrowser({
profileId: 'your_profile_id',
config: {
headless: false,
autoClose: false
}
});
// Attach Puppeteer to the running browser
const browser = await puppeteer.connect({
browserWSEndpoint: cdpResponse.data.webSocketDebuggerUrl,
defaultViewport: null
});
const page = await browser.newPage();
await page.goto('https://example.com');
console.log('Page title:', await page.title());Python SDK: Start and Stop a Browser Profile
python
from nstbrowser import NstbrowserClient
client = NstbrowserClient(api_key="your_api_key")
# Launch the browser profile
response = client.browsers.start_browser(profile_id="your_profile_id")
print(f"Browser started: {response}")
# Close the browser profile
response = client.browsers.stop_browser(profile_id="your_profile_id")
print(f"Browser stopped: {response}")Python SDK: Create a Profile Programmatically
python
from nstbrowser import NstbrowserClient
client = NstbrowserClient(api_key="your_api_key")
profile_data = {
"name": "My Automation Profile",
"platform": "Windows",
"kernelMilestone": "132"
}
response = client.profiles.create_profile(data=profile_data)
print(f"Profile created: {response}")Raw HTTP API
The local API is also callable directly without a SDK:
bash
# List all profiles
curl -H "x-api-key: your_api_key" \
http://localhost:8848/api/v2/profiles
# Launch a profile
curl -X POST \
-H "x-api-key: your_api_key" \
-H "Content-Type: application/json" \
-d '{"profileId":"your_profile_id"}' \
http://localhost:8848/api/v2/browsers/startPlaywright Integration
Playwright connects to a running Nstbrowser profile via the same CDP WebSocket endpoint used by Puppeteer. Retrieve the WebSocket URL from client.cdpEndpoints().connectBrowser(...) (Node) or the equivalent API call, then:
javascript
import { chromium } from 'playwright';
const browser = await chromium.connectOverCDP('ws://localhost:8848/...');
const page = await browser.newPage();
await page.goto('https://example.com');