Skip to content

Setup & ApiServer Configuration

Playwright integration in Mbbrowser supports three languages. You can choose the one that aligns best with your team's expertise. Installation steps vary slightly for each; please read the relevant section.


Choose Your Language

TIP

  • JavaScript (Node.js): Similar to Puppeteer; concise scripts. Recommended for frontend developers.
  • Python: Ideal for data analysis or web scraping; Mbbrowser manages the virtual environment for you.
  • Java: Seamless integration for enterprise projects or teams already using a Java stack.

1. JavaScript / TypeScript Environment

1. Install Node.js

Download the LTS Version (e.g., Node.js 20.x) from the Official Node.js Website.

Verify installation:

bash
node -v   # Should output v20.x.x or higher
npm -v

2. Create Project and Install Playwright

bash
# Create project folder
mkdir mb-playwright && cd mb-playwright

# Initialize npm project
npm init -y

# Install Playwright (Core library only; no need for built-in browsers, we use Mbbrowser)
npm install playwright

NOTE

During installation, Playwright may attempt to download browser files. Since we use Mbbrowser's browser, you can skip this by setting an environment variable:

bash
set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
npm install playwright

3. Install axios (For calling Mbbrowser ApiServer)

bash
npm install axios

2. Python Environment

1. Install Python

Download Python 3.8+ from the Official Python Website.

Make sure to check: ✅ Add Python to PATH during installation.

2. Mbbrowser Playwright Python Venv

IMPORTANT

Mbbrowser contains a built-in independent virtual environment for Playwright Python located at the python\Playwright\ subdirectory of your Mbbrowser installation path.

When running within the Mbbrowser Client's script manager, Mbbrowser activates this venv automatically.

If you wish to debug independently via the command line, manual activation is required:

bash
# Navigate to the python directory in the Mbbrowser installation path
cd "C:\Program Files (x86)\Mbbrowser_vX.X.X\python"
# Activate the virtual environment
Playwright\Scripts\activate
# You can now use pip or run playwright commands normally

3. Install Playwright Python Library

Once the virtual environment is activated:

bash
pip install playwright requests

NOTE

playwright will install necessary dependencies but you do not need to run playwright install to download browsers.


3. Java Environment

1. Install JDK

Download JDK 11 or 17 (17 LTS recommended) from Adoptium.

2. Mbbrowser Playwright Java Driver

IMPORTANT

Mbbrowser bundles necessary JAR files for Playwright Java in its installation directory:

Mbbrowser_Installation_Path\
└── lib\
    ├── playwright-1.48.0.jar
    ├── driver-bundle-1.48.0.jar
    └── gson-2.x.jar

Running Java scripts via the Mbbrowser script manager automatically extracts the driver-bundle and configures the environment.

3. Maven / Gradle Dependency

If using Maven:

xml
<dependency>
  <groupId>com.microsoft.playwright</groupId>
  <artifactId>playwright</artifactId>
  <version>1.50.0</version>
</dependency>

4. Enable Mbbrowser ApiServer (All Languages)

IMPORTANT

Regardless of language choice, you must start the ApiServer before your script can communicate with Mbbrowser!

Get App Authentication Info

  1. Open Mbbrowser client and log in.
  2. Go to Personal CenterAPI Settings.
  3. Obtain (or generate) your APP_ID and APP_KEY.

Start ApiServer

Open CMD with administrator privileges and navigate to the Mbbrowser installation directory:

bash
apiserver.exe --port=8186 --app_id=YOUR_APP_ID --app_key=YOUR_APP_KEY --hide=off
ParameterDescriptionRecommended Value
--portListening Port8186 (Default)
--app_idAuthentication IDFrom Personal Center
--app_keyAuthentication KeyFrom Personal Center
--hideHide browser?off (visible is better for debugging)

Upon success:

ApiServer started at http://127.0.0.1:8186

5. Obtain Environment Session_ID

In the Mbbrowser main panel, find your target environment:

  • Right-click → Copy Environment ID (Session_ID).
  • Format: 32-character hex string (e.g., 373808cb37bd63f5f7d92415e736e85f).

6. Understand ApiServer Response (ws field)

When calling /api/v1/browser/start, the returned data structure looks like this:

json
{
  "code": 0,
  "message": "success",
  "data": {
    "http": "127.0.0.1:9222",
    "ws": "ws://127.0.0.1:9222/devtools/browser/YOUR-BROWSER-ID"
  }
}
FieldMeaningUsage in Playwright
data.httpHTTP debugging addressPrimarily for Selenium.
data.wsWebSocket CDP AddressCrucial for Playwright

7. Setup Checklist

Before proceeding to the next chapter, ensure:

  • [ ] Language runtime (JS/Python/Java) is installed.
  • [ ] playwright library is installed.
  • [ ] ApiServer is running and http://127.0.0.1:8186/ is accessible.
  • [ ] You have the Session_ID for your target environment.
  • [ ] You understand that data.ws is the WebSocket address needed for Playwright.

TIP

Ready? The next chapter Quick Start: Connect provides complete, runnable scripts for all three languages.