Automation & RPA Integration Guide

Learn how to use NestBrowser's automation API with Selenium, Puppeteer, Playwright, and custom RPA workflows to automate browser profile management at scale.

NestBrowser exposes a local REST API that lets you programmatically control browser profiles. This enables powerful automation workflows — from simple script-driven logins to complex RPA pipelines managing hundreds of accounts.

How the Automation API Works

NestBrowser runs a local HTTP server (default: http://localhost:19222) when the application is open. This server provides endpoints to:

  • List and create browser profiles
  • Start and stop profiles
  • Connect automation frameworks via the WebSocket debugging port
  • Manage cookies and sessions programmatically

Connecting with Puppeteer

Puppeteer is the most common automation framework for NestBrowser integration.

Step 1: Get the Profile’s WebSocket URL

const axios = require('axios');

// Get list of profiles
const { data: profiles } = await axios.get('http://localhost:19222/api/v1/browser/list');

// Start a specific profile by ID
const profileId = profiles[0].id;
const { data: startResult } = await axios.post(
  `http://localhost:19222/api/v1/browser/start?id=${profileId}`
);

const wsEndpoint = startResult.ws.puppeteer;
// e.g., "ws://127.0.0.1:9222/devtools/browser/xxx"

Step 2: Connect Puppeteer to the Profile

const puppeteer = require('puppeteer-core');

const browser = await puppeteer.connect({
  browserWSEndpoint: wsEndpoint,
  defaultViewport: null,
});

const page = await browser.newPage();
await page.goto('https://www.amazon.com');

// Your automation logic here
await page.waitForSelector('#nav-link-accountList');

Step 3: Close the Profile After Automation

// Close the profile (optional — it stops the browser but keeps profile data)
await axios.post(`http://localhost:19222/api/v1/browser/stop?id=${profileId}`);

Connecting with Selenium WebDriver

NestBrowser’s API is compatible with ChromeDriver, so Selenium works with minimal configuration.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import requests

# Start the profile (Python example)
profile_id = "your-profile-id"
result = requests.post(f"http://localhost:19222/api/v1/browser/start?id={profile_id}")
debugger_address = result.json()["ws"]["selenium"]
# e.g., "127.0.0.1:9223"

# Connect Selenium
options = Options()
options.add_experimental_option("debuggerAddress", debugger_address)
driver = webdriver.Chrome(options=options)

driver.get("https://www.tiktok.com")
# Your Selenium logic here

Connecting with Playwright

const { chromium } = require('playwright');
const axios = require('axios');

// Start the profile
const { data } = await axios.post(
  `http://localhost:19222/api/v1/browser/start?id=${profileId}`
);

// Connect Playwright
const browser = await chromium.connectOverCDP(data.ws.puppeteer);
const context = browser.contexts()[0];
const page = context.pages()[0];

await page.goto('https://www.facebook.com');

Managing Multiple Profiles in Parallel

The API supports concurrent profile operations, making it easy to run automation on multiple accounts simultaneously.

const axios = require('axios');
const puppeteer = require('puppeteer-core');

async function automateProfile(profileId, task) {
  // Start profile
  const { data } = await axios.post(
    `http://localhost:19222/api/v1/browser/start?id=${profileId}`
  );
  
  const browser = await puppeteer.connect({
    browserWSEndpoint: data.ws.puppeteer,
    defaultViewport: null,
  });
  
  try {
    const page = await browser.newPage();
    await task(page);
  } finally {
    await axios.post(
      `http://localhost:19222/api/v1/browser/stop?id=${profileId}`
    );
  }
}

// Run 5 profiles in parallel
const profiles = ['id1', 'id2', 'id3', 'id4', 'id5'];
await Promise.all(
  profiles.map(id => automateProfile(id, async (page) => {
    await page.goto('https://example.com');
    // Your task logic
  }))
);

Common Automation Use Cases

Automated Account Warming

async function warmAccount(page) {
  // Simulate natural browsing behavior
  await page.goto('https://www.amazon.com');
  await page.waitForTimeout(2000 + Math.random() * 3000);
  
  // Browse some product categories
  const categories = [
    '/s?k=electronics',
    '/s?k=books',
    '/s?k=clothing'
  ];
  
  for (const cat of categories) {
    await page.goto(`https://www.amazon.com${cat}`);
    await page.waitForTimeout(3000 + Math.random() * 5000);
    // Simulate scroll
    await page.evaluate(() => window.scrollBy(0, 500));
    await page.waitForTimeout(1000 + Math.random() * 2000);
  }
}

Data Collection

async function collectProductData(page, searchTerm) {
  await page.goto(`https://www.amazon.com/s?k=${encodeURIComponent(searchTerm)}`);
  
  const products = await page.evaluate(() => {
    return Array.from(document.querySelectorAll('[data-component-type="s-search-result"]'))
      .map(el => ({
        title: el.querySelector('h2 span')?.textContent,
        price: el.querySelector('.a-price-whole')?.textContent,
        rating: el.querySelector('.a-icon-alt')?.textContent,
        asin: el.getAttribute('data-asin'),
      }));
  });
  
  return products;
}

Scheduled Tasks with Cron

const cron = require('node-cron');

// Check inventory and update listings daily at 9 AM
cron.schedule('0 9 * * *', async () => {
  console.log('Starting daily inventory check...');
  
  const profiles = await getActiveSellerProfiles();
  for (const profile of profiles) {
    await automateProfile(profile.id, async (page) => {
      await checkInventory(page, profile.storeId);
    });
  }
});

API Reference

GET /api/v1/browser/list

Returns all browser profiles.

Response:

[
  {
    "id": "profile-uuid",
    "name": "Amazon Store A",
    "created_at": "2024-01-15T10:00:00Z",
    "last_used": "2024-03-01T14:22:00Z"
  }
]

POST /api/v1/browser/start?id={profileId}

Starts a browser profile and returns connection details.

Response:

{
  "code": 0,
  "ws": {
    "puppeteer": "ws://127.0.0.1:9222/devtools/browser/xxx",
    "selenium": "127.0.0.1:9222"
  }
}

POST /api/v1/browser/stop?id={profileId}

Stops a running profile.

Best Practices

Add human-like delays: Real users don’t click at machine speed. Add random delays between actions (e.g., await page.waitForTimeout(800 + Math.random() * 1500)).

Handle errors gracefully: Always wrap automation code in try/catch and ensure profiles are properly closed even when errors occur.

Avoid running too many concurrent profiles: The number of profiles you can run simultaneously depends on your machine’s RAM. A general guideline: 100–200MB per active profile.

Keep automation code separate from profile management: Your automation scripts should be reusable across different profile IDs.

Next Steps