API & Task Automation

Puppeteer, Selenium, and Playwright

  • Home
  • Task automation via API
  • Puppeteer, Selenium, and Playwright
  • Playwright automation example

Playwright Automation Example

Author Yelena V (Updated on March 5, 2026)

Updated on March 5, 2026

Playwright is an open-source automation library designed to test web applications and automatically interact with web browsers. It provides comprehensive control over browser actions, including navigation, form filling, element clicking, and extracting data from web pages.

In this article, we will provide a simple script to launch a browser profile and connect it to Playwright.

You can use Playwright to automatically mimic browser profiles for your web crawlers. Please note that Stealthfox in Multilogin is not yet available in Playwright.

Before You Begin

JavaScript

  • Download Node.js from the official website and install it
  • Make sure Node.js and npm (Node Package Manager) are installed correctly:
node -v 
npm -v
node -v 
npm -v
  • Create a project directory, then run this command to initialize a new Node.js project and create a package.json file:
package.json
npm init -y
npm init -y
  • Install Playwright as a dependency for your project:
Blog Post Img
npm install playwright
npm install playwright
  • Install the Axios and MD5 libraries:
npm install axios 
npm install md5
npm install axios 
npm install md5
  • Insert your values into the following variables in the script: email: your Multilogin account email password: your Multilogin account password (no MD5 encryption needed) folder_id, profile_id: find these values using the guides on DevTools or Postman
  • email: your Multilogin account email
email
  • password: your Multilogin account password (no MD5 encryption needed)
password
  • folder_id, profile_id: find these values using the guides on DevTools or Postman
folder_id
profile_id

Python

  • Install the following Python library: playwright
  • Requirements
  • playwright
  • Install the necessary browser binaries:
playwright install
playwright install
Google SERP Img
  • Insert your values into the following variables in the script:

USERNAME: Your Multilogin account email

PASSWORD: Your Multilogin account password (no MD5 encryption needed)

FOLDER_ID, PROFILE_ID: Find these values using the guides in DevTools or Postman

  • USERNAME: Your Multilogin account email
USERNAME
  • PASSWORD: Your Multilogin account password (no MD5 encryption needed)
PASSWORD
  • FOLDER_ID, PROFILE_ID: Find these values using the guides in DevTools or Postman
FOLDER_ID
PROFILE_ID

Run Script

JavaScript

  • Launch the application, as it can open the profile page
  • Ensure Playwright is compatible with the current Mimic core version – check the Playwright and Mimic release notes
  • Run the .js file using automation code
.js

Script Example

UK Proxy Img
const { chromium } = require('playwright');
const md5 = require ('md5');
const axios = require('axios');
const HEADERS =  { 
  "Content-Type": "application/json", 
  "Accept": "application/json",
};
const acc_info = {
  // Insert your account information in both variables below
  "email": "",
  "password": md5("")
};
async function get_token() {
  const signIn_URL = "https://api.multilogin.com/user/signin";
  try {
    const response = await axios.post(signIn_URL, acc_info, { headers: HEADERS });
    return response.data.data.token;
  } catch (error) {
    console.log(error.message);
    console.log("Response data:", error.response.data);
    return false;
  }
};
// Insert the Folder ID and the Profile ID below
const folder_id = "";
const profile_id = "";
async function start_browserProfile(){
  const token = await get_token();
  if (!token) return;
  // Update HEADERS with bearer token retrived from the get_token function
  HEADERS.Authorization = 'Bearer ' + token;
  // Launch a profile defining "Playwright" as automation type
  const profileLaunch_URL = `https://launcher.mlx.yt:45001/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}`;
    // if you prefer to connect with browserWSEndpoint, try to get the webSocketDebuggerUrl by following request
    // const {data : {webSocketDebuggerUrl}} = await axios.get(`${browserURL}/json/version`)
    const browser = await chromium.connectOverCDP(browserURL,{timeout:10000});
    const context = browser.contexts()[0];
    const page = await context.newPage();
    await page.goto("https://multilogin.com/");
    await page.screenshot({path: "example.png"});
    await page.close();
  } catch (error) {
    console.log("Error:", error.message);
    if (error.response) {
      console.log("Response data:", error.response.data); 
  } 
  }
};
start_browserProfile();
const { chromium } = require('playwright');
const md5 = require ('md5');
const axios = require('axios');
const HEADERS =  { 
  "Content-Type": "application/json", 
  "Accept": "application/json",
};
const acc_info = {
  // Insert your account information in both variables below
  "email": "",
  "password": md5("")
};
async function get_token() {
  const signIn_URL = "https://api.multilogin.com/user/signin";
  try {
    const response = await axios.post(signIn_URL, acc_info, { headers: HEADERS });
    return response.data.data.token;
  } catch (error) {
    console.log(error.message);
    console.log("Response data:", error.response.data);
    return false;
  }
};
// Insert the Folder ID and the Profile ID below
const folder_id = "";
const profile_id = "";
async function start_browserProfile(){
  const token = await get_token();
  if (!token) return;
  // Update HEADERS with bearer token retrived from the get_token function
  HEADERS.Authorization = 'Bearer ' + token;
  // Launch a profile defining "Playwright" as automation type
  const profileLaunch_URL = `https://launcher.mlx.yt:45001/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}`;
    // if you prefer to connect with browserWSEndpoint, try to get the webSocketDebuggerUrl by following request
    // const {data : {webSocketDebuggerUrl}} = await axios.get(`${browserURL}/json/version`)
    const browser = await chromium.connectOverCDP(browserURL,{timeout:10000});
    const context = browser.contexts()[0];
    const page = await context.newPage();
    await page.goto("https://multilogin.com/");
    await page.screenshot({path: "example.png"});
    await page.close();
  } catch (error) {
    console.log("Error:", error.message);
    if (error.response) {
      console.log("Response data:", error.response.data); 
  } 
  }
};
start_browserProfile();

Python

  • Launch the application, as it can open the profile page
  • Ensure Playwright is compatible with the current Mimic core version – check the Playwright and Mimic release notes
  • Run the .py file using automation code
.py

Script Example

import hashlib
import requests
import time
from playwright.sync_api import sync_playwright
MLX_BASE = "https://api.multilogin.com"
HEADERS = {"Accept": "application/json", "Content-Type": "application/json"}
# TODO: Insert your account information in both variables below
USERNAME = ""
PASSWORD = ""
# TODO: Insert the Folder ID and the Profile ID below
FOLDER_ID = ""
PROFILE_ID = ""
def sign_in() -> str:
    payload = {
        "email": USERNAME,
        "password": hashlib.md5(PASSWORD.encode()).hexdigest(),
    }
    r = requests.post(f"{MLX_BASE}/user/signin", json=payload)
    if r.status_code != 200:
        print(f"nError during login: {r.text}n")
    else:
        response = r.json()["data"]
        token = response["token"]
        return token
HEADERS["Authorization"] = f"Bearer {sign_in()}"
def start_profile():
    with sync_playwright() as pw:
        resp = requests.get(
            f"https://launcher.mlx.yt:45001/api/v2/profile/f/{FOLDER_ID}/p/{PROFILE_ID}/start?automation_type=playwright&headless_mode=false",
            headers=HEADERS)
        resp_json = resp.json()
        if resp.status_code != 200:
            print(f"nError while starting profile: {resp.text}n")
            return
        else:
            print(f"nProfile {PROFILE_ID} started.n")
            browserPort = resp_json["data"]["port"]
            browserURL = f"http://127.0.0.1:{browserPort}"
            # if you prefer to connect with browserWSEndpoint, try to get the webSocketDebuggerUrl by following request
            # response = requests.get(f'{browserURL}/json/version')
            # browser_ws_endpoint = response.json()["webSocketDebuggerUrl"]
            browser = pw.chromium.connect_over_cdp(endpoint_url=browserURL)
            context = browser.contexts[0]
            page = context.new_page()
            page.goto('https://www.multilogin.com')
            time.sleep(5)
            page.screenshot(path='example.png')   
            page.close()
start_profile()
import hashlib
import requests
import time
from playwright.sync_api import sync_playwright
MLX_BASE = "https://api.multilogin.com"
HEADERS = {"Accept": "application/json", "Content-Type": "application/json"}
# TODO: Insert your account information in both variables below
USERNAME = ""
PASSWORD = ""
# TODO: Insert the Folder ID and the Profile ID below
FOLDER_ID = ""
PROFILE_ID = ""
def sign_in() -> str:
    payload = {
        "email": USERNAME,
        "password": hashlib.md5(PASSWORD.encode()).hexdigest(),
    }
    r = requests.post(f"{MLX_BASE}/user/signin", json=payload)
    if r.status_code != 200:
        print(f"nError during login: {r.text}n")
    else:
        response = r.json()["data"]
        token = response["token"]
        return token
HEADERS["Authorization"] = f"Bearer {sign_in()}"
def start_profile():
    with sync_playwright() as pw:
        resp = requests.get(
            f"https://launcher.mlx.yt:45001/api/v2/profile/f/{FOLDER_ID}/p/{PROFILE_ID}/start?automation_type=playwright&headless_mode=false",
            headers=HEADERS)
        resp_json = resp.json()
        if resp.status_code != 200:
            print(f"nError while starting profile: {resp.text}n")
            return
        else:
            print(f"nProfile {PROFILE_ID} started.n")
            browserPort = resp_json["data"]["port"]
            browserURL = f"http://127.0.0.1:{browserPort}"
            # if you prefer to connect with browserWSEndpoint, try to get the webSocketDebuggerUrl by following request
            # response = requests.get(f'{browserURL}/json/version')
            # browser_ws_endpoint = response.json()["webSocketDebuggerUrl"]
            browser = pw.chromium.connect_over_cdp(endpoint_url=browserURL)
            context = browser.contexts[0]
            page = context.new_page()
            page.goto('https://www.multilogin.com')
            time.sleep(5)
            page.screenshot(path='example.png')   
            page.close()
start_profile()

In this article

  • Before you start
  • Run the script

Multilogin Community

Stay informed, share your thoughts, and interact with others!

Read more related content

Related Articles

  • Introduction to automation scripts
  • Selenium browser automation example
  • Puppeteer automation example
  • How to solve WebDriver connection issues
  • How to choose the best automation framework