Skip to content

Quick Start: Taking Control of Mbbrowser Environment

This chapter provides a Python script that you can directly copy and run, leading you from scratch to successfully taking control of an Mbbrowser fingerprint environment and completing your first automation task.


Full Script (Copy-and-use)

Create a file named start_selenium.py, paste the following code, and modify the configuration section:

python
import requests
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

# ============================
# Configuration Section: Modify with your own info
# ============================
API_URL    = "http://127.0.0.1:8186"
SESSION_ID = "replace_with_your_session_id"        # Obtain via right-click → Copy Environment ID in Mbbrowser
# Path to chromedriver.exe in the Mbbrowser directory (or set to None for Selenium Manager auto-match)
DRIVER_PATH = r"C:\Program Files (x86)\Mbbrowser_v7.10.20.219\chromedriver.exe"


def start_browser():
    """
    Step 1: Tell Mbbrowser ApiServer to open a specific environment.
    Step 2: Obtain the debuggerAddress from the return value.
    Step 3: Use Selenium to take control of that environment.
    Step 4: Execute business logic.
    """

    # ── Step 1: Open Mbbrowser Environment ──────────────────────────
    print("⏳ Starting Mbbrowser fingerprint environment...")
    try:
        response = requests.post(
            f"{API_URL}/api/v1/browser/start",
            json={"Session_ID": SESSION_ID},
            timeout=30
        )
        data = response.json()
    except requests.exceptions.ConnectionError:
        print("❌ Could not connect to ApiServer. Ensure it is started and the port is correct!")
        return

    if data.get("code") != 0:
        print(f"❌ Environment startup failed: {data.get('message')}")
        return

    # ── Step 2: Extract Remote Debugging Address ──────────────────────
    # data["data"]["http"] format: 127.0.0.1:9222
    debugger_address = data["data"]["http"]
    print(f"✅ Environment started. Remote debugging address: {debugger_address}")

    # ── Step 3: Configure Selenium to Take Control ───────────────────
    chrome_options = Options()
    # This is the key parameter for taking over an existing browser (instead of creating a new one)!
    chrome_options.add_experimental_option("debuggerAddress", debugger_address)

    # If you have the chromedriver included with Mbbrowser, specify its path;
    # Otherwise, set to None for Selenium Manager to handle it automatically.
    if DRIVER_PATH:
        service = Service(executable_path=DRIVER_PATH)
        driver = webdriver.Chrome(service=service, options=chrome_options)
    else:
        driver = webdriver.Chrome(options=chrome_options)

    print("🎉 Selenium takeover successful!")

    # ── Step 4: Execute Your Business Logic ─────────────────────────
    try:
        # Navigate to target URL
        driver.get("https://www.mbbrowser.com")
        print(f"📄 Current Page Title: {driver.title}")

        # Wait for 3 seconds for observation
        time.sleep(3)

        print("✅ Script execution finished!")
    finally:
        # IMPORTANT: This only "disconnects the Selenium connection."
        # The Mbbrowser environment will continue to run.
        # To close the browser completely, call the /api/v1/browser/stop API.
        driver.quit()


if __name__ == "__main__":
    start_browser()

Run the script:

bash
python start_selenium.py

Expected Output

⏳ Starting Mbbrowser fingerprint environment...
✅ Environment started. Remote debugging address: 127.0.0.1:9222
🎉 Selenium takeover successful!
📄 Current Page Title: MBBrowser Anti-association Browser - Multi-Account Solution
✅ Script execution finished!

Line-by-Line Analysis

1. Call ApiServer to Start Environment

python
response = requests.post(
    f"{API_URL}/api/v1/browser/start",
    json={"Session_ID": SESSION_ID}
)
  • This step tells Mbbrowser: "Help me open the fingerprint environment with Session_ID XXX."
  • Upon receiving the request, ApiServer starts the corresponding Chrome instance and opens a remote debugging port.

2. Extract debuggerAddress

python
debugger_address = data["data"]["http"]  # e.g., 127.0.0.1:9222
  • Information in the http field is Chrome's Remote Debugging Port Address (usually 127.0.0.1:PORT).
  • Each Mbbrowser environment has a unique port number automatically assigned by Mbbrowser, permitting concurrent runs without conflict.

3. Set debuggerAddress to Take Control (Crucial Step!)

python
chrome_options.add_experimental_option("debuggerAddress", debugger_address)
driver = webdriver.Chrome(options=chrome_options)

This is the essential difference between Mbbrowser Selenium automation and regular Selenium:

ActionRegular SeleniumMbbrowser Selenium
Create DriverStarts a new, blank Chrome windowConnects to and takes control of an existing Mbbrowser browser
FingerprintNone; naked stateFull fingerprints (UA, Canvas, WebGL, IP all in place)
Cookie StatusEmpty; requires re-loginRetains previous login state (if previously logged in)

4. Post-execution Handling

python
driver.quit()  # Disconnect Selenium control (Mbbrowser environment keeps running)

NOTE

driver.quit() only disconnects Selenium's control path from the browser—it does not close the Mbbrowser window.

To close the browser completely, invoke:

python
requests.post(f"{API_URL}/api/v1/browser/stop", json={"Session_ID": SESSION_ID})

Troubleshooting

❓ Error: Cannot connect to the Service

Reason: chromedriver.exe version mismatch with the Mbbrowser kernel.

Solution:

  1. Use the chromedriver.exe included in the Mbbrowser directory and specify its path in Service.
  2. Alternatively, remove the DRIVER_PATH config (set to None) and let Selenium Manager handle it.

❓ Error: ConnectionError: Cannot connect to ApiServer

Reason: ApiServer is not running, or the port is occupied.

Solution:

  1. Confirm that the ApiServer terminal window is still running.
  2. Confirm the port in API_URL matches the --port parameter.
  3. Check if the firewall is blocking port 8186.

❓ Error: code != 0: Environment startup failed

Reason: Session_ID is incorrect, or the environment is already running.

Solution:

  1. Confirm in Mbbrowser that you copied the correct Session_ID.
  2. If the environment is already running, call the stop interface before restarting.

❓ Browser opens, but not in logged-in state

Reason: This is the first time the environment is opened; you haven't logged in yet, so Cookies are empty.

Solution: This is normal. Next, read Core API Reference to learn how to inject Cookies or automate login.


TIP

Script running? The next chapter Core API Reference will teach you how to perform more complex operations with Selenium: element positioning, typing, clicking, waiting, and screenshots... everything is there!