Skip to content

Upgrading instructions for Playwright engine

Playwright Automation Engine Support

New Feature | Major Update | Recommended


📋 Feature Overview

This update adds Playwright engine support to MBBrowser's automation script functionality, forming three major automation solutions together with existing Puppeteer and Selenium engines, providing users with more powerful and modern browser automation capabilities.

Update Highlights: Supports JavaScript, Python, and Java languages, automatic environment configuration, zero-configuration usage!


✨ Core Features

1. Comprehensive Language Support

LanguageEngine TypeRuntime EnvironmentFeatures
JavaScriptPlaywrightNode.jsNative support, optimal performance
PythonPlaywrightVirtual EnvironmentAutomatic virtual environment activation, environment isolation
JavaPlaywrightJDK + Node.jsAutomatic driver extraction, automated configuration

2. Intelligent Environment Management

Python Virtual Environment

bash
# Auto-generated startup script
call Playwright\Scripts\activate
Playwright\Scripts\python.exe "script_path"

✅ Automatic virtual environment activation
✅ Environment isolation, avoiding conflicts

Java Driver Auto-extraction

bash
# Auto-extraction on first run
if not exist package\cli.js (
  jar xf lib\driver-bundle.jar
  move driver\win32_x64\package package
)

✅ Smart detection
✅ Automatic extraction and configuration

Independent Bat File Management

Python non-debug mode:
Each script generates an independent bat file (named with SESSION_UNIQUE_ID)

✅ Avoid concurrent conflicts
✅ Automatic cleanup mechanism

3. Unified CDP Connection Method

All languages connect to the launched Chrome instance via Chrome DevTools Protocol (CDP):

javascript
// JavaScript
const browser = await chromium.connectOverCDP(ws_endpoint);
python
# Python
browser = p.chromium.connect_over_cdp(ws_endpoint)
java
// Java
Browser browser = playwright.chromium().connectOverCDP(ws_endpoint);

🆚 Three Engine Comparison

FeaturePuppeteerSeleniumPlaywright (New)
Language SupportJS onlyJS/Python/JavaJS/Python/Java
Connection MethodWebSocketWebDriverCDP (Faster)
API Modernization⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Cross-browserChrome onlyMultiple browsersChrome/Firefox/Safari
Auto-waitManual requiredLimited supportSmart auto-wait
Network InterceptionSupportedNot supportedStrong support
Multi-tabSupportedSupportedNative excellent support
Community ActivityHighHighVery High (Microsoft maintained)

🔧 Technical Implementation Highlights

1. Intelligent Script Identification System

cpp
std::string g_sScriptFlag[3][3] = {
    {"std_mbscript_pup_js", "", ""},              // Puppeteer
    {"", "std_mbscript_sele_py", "std_mbscript_sele_jv"},  // Selenium
    {"std_mbscript_play_js", "std_mbscript_play_py", "std_mbscript_play_jv"}  // Playwright
};

✅ Automatically identifies script types through identifiers, ensuring correct runtime environment

2. Independent Bat File Management

Python Script Non-debug Mode:

  • Each script generates an independent bat file (named with SESSION_UNIQUE_ID)
  • Avoids multi-script concurrent conflicts
  • Automatic cleanup mechanism

Java Script Playwright Type:

  • Automatically detects and extracts drivers
  • Sets Node.js path
  • Intelligent error handling and prompts

3. Automatic Port and Key Replacement

Automatically replaces connection information in scripts at runtime:

javascript
// JavaScript & Python Playwright
size_t posStart = sJs.find("ws://localhost");
sJs.replace(sJs.begin() + posStart, sJs.begin() + posEnd, 
           pItem->sChromeKey.c_str());
java
// Java Playwright
size_t posStart = sJs.find("String ws_endpoint = \"");
sJs.replace(sJs.begin() + posStart, sJs.begin() + posEnd, 
           pItem->sChromeKey.c_str());

📝 Standard Script Templates

JavaScript Playwright Template

javascript
const { chromium } = require('playwright');
const ws_endpoint = 'ws://localhost:9223/...';  // Auto-replaced

const browser = await chromium.connectOverCDP(ws_endpoint);
// Get existing page or create new page
// Execute automation operations...

Python Playwright Template

python
from playwright.sync_api import sync_playwright
ws_endpoint = "ws://localhost:9234/..."  # Auto-replaced

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(ws_endpoint)
    # Automation operations...

Java Playwright Template

java
import com.microsoft.playwright.*;

System.setProperty("playwright.skip.browser.download", "1");
Playwright playwright = Playwright.create(...);
Browser browser = playwright.chromium().connectOverCDP(ws_endpoint);
// Automation operations...

🚀 User Experience Enhancement

Zero-Configuration Startup

  1. User only needs to select "Playwright" engine
  2. Select language (JS/Python/Java)
  3. Write script, run with one click
  4. All environment configuration completed automatically

Environment Isolation

  • ✅ Python uses independent virtual environment (Playwright directory)
  • ✅ Java driver auto-extraction, no system pollution
  • ✅ JavaScript uses project-level node_modules

Intelligent Error Handling

  • ✅ Missing driver? Auto-extract
  • ✅ Node.js not found? Auto-configure PATH
  • ✅ Detailed error logs and prompts

📊 Performance Comparison

MetricSeleniumPuppeteerPlaywright
Startup Speed2-3 seconds1-2 seconds1-2 seconds
Operation ResponseSlowerFastFastest
Stability⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Resource UsageMediumLowLow

📦 System Requirements

Basic Environment

  • Node.js (Existing, shared with Puppeteer)
  • Python Virtual Environment (New: python\Playwright)
  • JDK (Existing, shared with Selenium)

New Dependency Packages

Python

bash
# In virtual environment
pip install playwright

Java

lib/
  ├── playwright-1.48.0.jar
  ├── driver-bundle-1.48.0.jar
  ├── driver-1.48.0.jar
  └── gson-2.x.jar (and other dependencies)

JavaScript

bash
npm install playwright

🎯 Use Cases

Playwright Advantage Scenarios

Modern Web Applications

  • SPA application auto-waiting
  • Complex interaction support
  • Better asynchronous handling

Multi-tab Operations

  • Native multi-tab management
  • Context isolation
  • Concurrent operation optimization

Network Layer Control

  • Request/response interception and modification
  • API testing
  • Performance analysis

Cross-browser Testing

  • Same code for multiple browsers
  • Compatibility guarantee
  • Unified API

🔄 Migration Guide

From Selenium to Playwright

Selenium Python:

python
from selenium import webdriver
driver = webdriver.Chrome(...)
driver.get('https://example.com')

Playwright Python:

python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(ws_endpoint)
    page = browser.contexts[0].pages[0]
    page.goto('https://example.com')

From Puppeteer to Playwright

Puppeteer:

javascript
const puppeteer = require('puppeteer-core');
const browser = await puppeteer.connect({...});

Playwright:

javascript
const { chromium } = require('playwright');
const browser = await chromium.connectOverCDP(ws_endpoint);

💡 Upgrade Recommendations

✅ Scenarios Suitable for Playwright

  • Need modern API and better asynchronous support
  • Need network layer control (intercept/modify requests)
  • Need multi-tab/multi-context management
  • Need cross-browser testing
  • Need more stable automation scripts

⚡ Scenarios to Continue Using Selenium

  • Existing large Selenium script base, high migration cost
  • Need mobile browser support (Appium)
  • Team more familiar with Selenium ecosystem

⚡ Scenarios to Continue Using Puppeteer

  • Only need Chrome/Chromium support
  • Simple scripts, no complex functionality needed
  • Pursuit of minimal dependencies

🏗️ Technical Architecture

MBBrowser

CScriptManager

┌───────────┬───────────┬────────────┐
│ Puppeteer │ Selenium  │ Playwright │
│  JS only  │ JS/Py/Java│ JS/Py/Java│
└───────────┴───────────┴────────────┘

Chrome DevTools Protocol (CDP)

Chrome 140 Instance

🎉 Summary

This update brings to MBBrowser:

  • Enhanced Functionality: Added third automation engine option
  • Better Development Experience: More modern API, less boilerplate code
  • Improved Stability: Microsoft official maintenance, long-term support guarantee
  • Flexibility: Three languages, meeting different developer needs
  • Intelligence: Automatic environment configuration, zero-configuration usage

Playwright's addition makes MBBrowser more competitive in the browser automation field! 🚀


⚡ Quick Start

Step 1: Select Engine

In the automation script management interface, select "Playwright" engine type

Step 2: Select Language

Choose according to needs: JavaScript, Python, or Java

Step 3: Write Script

System automatically generates standard templates for the selected language, including Chrome connection code

Step 4: Run with One Click

Click run, system automatically:

  1. Detects and configures runtime environment
  2. Replaces connection endpoint and key
  3. Activates necessary virtual environment (Python)
  4. Extracts drivers (Java)
  5. Executes script and connects to Chrome instance

⚠️ Important Notes:

  • Using Java language requires installing corresponding language environment packages. You can download Java environment packages by creating a new script window, selecting Playwright script, and clicking Java language download
  • When using Playwright scripts with Python, if you need to install other components, please first execute "Playwright\Scripts\activate" and then call pip for installation
  • When running the script, it is recommended to first set the client to run in standalone mode

Version Update Date: December 2025
Technical Support: Playwright 1.48.0 | Selenium 4.25.0 | Puppeteer Latest