Skip to main content

Playwright automation example

Playwright is a powerful open-source library for automating web browsers, enabling tasks like navigation, form filling, and data extraction. When combined with Indigo X, it allows you to manage and automate Mimic browser profiles for advanced web scraping and testing workflows.

In this guide, we'll walk through setting up Playwright to automate a Mimic browser profile using both JavaScript and Python. You'll learn how to authenticate with Indigo X, launch a browser profile, and perform basic automation tasks.

info

Playwright for Stealthfox is not yet available in Indigo X. Ensure compatibility between Playwright and the Mimic core version by checking the release notes.

Prerequisites

Before you begin, ensure you have the following:

JavaScript

  • Node.js: Download and install from the official website.
  • Verify installation:
    node -v
    npm -v
  • A Indigo X account with your email, password, folder_id, and profile_id (find these using DevTools or Postman).
  • Project setup:
    mkdir playwright-indigo
    cd playwright-indigo
    npm init -y
    npm install playwright axios md5

Python

  • Python 3.x: Ensure it's installed.
  • Required libraries:
    pip install requests playwright
    playwright install
  • A Indigo X account with your USERNAME, PASSWORD, FOLDER_ID, and PROFILE_ID.
tip

Ensure the Indigo X agent is connected to enable profile launching.

Automation Workflow

The automation process involves:

  1. Authenticating with Indigo X to obtain a token.
  2. Launching a Mimic browser profile via the Indigo X API.
  3. Connecting Playwright to the browser profile.
  4. Performing actions like navigating to a webpage and taking a screenshot.

Below are example scripts for both JavaScript and Python.

Example Scripts

JavaScript Example

This script authenticates with Indigo X, launches a Mimic browser profile, and automates a simple task using Playwright.

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

const HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json",
};

const acc_info = {
email: "YOUR_EMAIL", // Replace with your Indigo X email
password: md5("YOUR_PASSWORD"), // Replace with your password
};

const folder_id = "YOUR_FOLDER_ID"; // Replace with your folder ID
const profile_id = "YOUR_PROFILE_ID"; // Replace with your profile ID

async function get_token() {
const signIn_URL = "https://api.indigobrowser.com/user/signin";
try {
const response = await axios.post(signIn_URL, acc_info, { headers: HEADERS });
return response.data.data.token;
} catch (error) {
console.error("Error:", error.message);
console.error("Response data:", error.response?.data);
return false;
}
}

async function start_browserProfile() {
const token = await get_token();
if (!token) return;

HEADERS.Authorization = `Bearer ${token}`;
const profileLaunch_URL = `https://launcher.indigobrowser.com:45011/api/v2/profile/f/${folder_id}/p/${profile_id}/start?automation_type=playwright&headless_mode=false`;

try {
const response = await axios.get(profileLaunch_URL, { headers: HEADERS });
const browserURL = `http://127.0.0.1:${response.data.data.port}`;
const browser = await chromium.connectOverCDP(browserURL, { timeout: 10000 });
const context = browser.contexts()[0];
const page = await context.newPage();
await page.goto("https://indigobrowser.com/");
await page.screenshot({ path: "example.png" });
await page.close();
} catch (error) {
console.error("Error:", error.message);
console.error("Response data:", error.response?.data);
}
}

start_browserProfile();

Running the Script

  1. Save the script as index.js.
  2. Ensure the Indigo X agent is running.
  3. Run the script:
    node index.js

Configuration Details

VariableDescriptionHow to Find
email / USERNAMEYour Indigo X account emailYour account settings
password / PASSWORDYour Indigo X account password (MD5 hashed for API)Your account settings
folder_id / FOLDER_IDID of the folder containing the browser profileUse DevTools or Postman
profile_id / PROFILE_IDID of the specific browser profileUse DevTools or Postman)

Troubleshooting

caution
  • Ensure the Indigo X agent is connected before running the script.
  • Verify Playwright compatibility with the Mimic core version in the release notes.
  • If authentication fails, double-check your email/USERNAME and password/PASSWORD.
  • For network errors, ensure the Indigo X API endpoints (api.indigobrowser.com and launcher.indigobrowser.com) are accessible.