Puppeteer automation example
Use Puppeteer to automate a Multilogin Mimic browser profile by starting the profile with automation_type=puppeteer, getting the automation port from the start response, and connecting Puppeteer to that local port.
➡️ Keep the Multilogin desktop app running → start the browser profile through the API → get data.port from the response → connect Puppeteer to http://127.0.0.1:<port>.
Puppeteer works with Mimic browser profiles. Legacy Stealthfox profiles don't support Puppeteer.
To start automating, check these resources first: Getting started with automation scripting.
This guide covers browser-profile automation. For native Android app automation on Multilogin cloud phones, use ADB or Appium.
Who can use this script?
- 👨💻 Account owners and team members
- 💰 Pro 10 and higher plans
How the connection works
-
The script starts the Multilogin browser profile with
automation_type=puppeteer -
Multilogin returns the automation port in
data.port -
The script builds
http://127.0.0.1:<port> -
puppeteer.connect()connects to the already-running Multilogin profile - Puppeteer can then open pages and run your browser actions
Before you start
- Download Node.js from the official website and install it
- Ensure Node.js and npm (Node Package Manager) are installed correctly:
node -v
npm -v- Create a project directory, then run this command to initialize a new Node.js project and create a
package.jsonfile:
npm init -y- Install Puppeteer as a dependency for your project:
npm install puppeteer- Install Axios:
npm install axios- Insert your values into the below variables in the script:
- Replace
https://multilogin.com/with the website you need in the following line:
await page.goto("https://multilogin.com/");Need the profile ID? You can copy it directly from the Multilogin interface. Learn how: How to copy profile IDs in Multilogin.
Running the script
- Launch the app, as it makes profile launching possible
- Use a Puppeteer version compatible with the Chromium version used by the current Mimic core. If Puppeteer fails to connect after a core update, check the current Mimic core and Puppeteer compatibility before changing the script.
- Run the
.jsfile with your automation codeMake sure to run the automation code in the same folder/project as
package.jsonfile.
Script example
const puppeteer = require('puppeteer');
const axios = require('axios');
const HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json",
};
// Insert your automation token in the variable below
const API_TOKEN = "";
// Insert the Folder ID and the Profile ID below
const folder_id = "";
const profile_id = "";
async function start_browserProfile() {
// Add the automation token to the request headers
HEADERS.Authorization = 'Bearer ' + API_TOKEN;
// Launch a profile defining "Puppeteer" as automation type
const profileLaunch_URL = `https://launcher.mlx.yt:45001/api/v2/profile/f/${folder_id}/p/${profile_id}/start?automation_type=puppeteer&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 puppeteer.connect({
browserURL: browserURL,
timeout: 10000
});
const page = await browser.newPage();
await page.goto("https://multilogin.com/");
await page.screenshot({
path: "example.png"
})
await page.close();
// Disconnect Puppeteer so the script can exit
await browser.disconnect();
// Stop the profile
await axios.get(`https://launcher.mlx.yt:45001/api/v1/profile/stop/p/${profile_id}`, { headers: HEADERS });
} catch (error) {
console.log("Error:", error.message);
if (error.response) {
console.log("Response data:", error.response.data);
}
}
};
start_browserProfile();Expected result: Multilogin starts the selected Mimic browser profile, Puppeteer connects to its returned automation port, opens the target webpage, and saves example.png in your project folder.
Troubleshooting
Why can't Puppeteer connect to the profile?
Check that:
- The Multilogin desktop app is running
-
folder_idandprofile_idare correct - The browser profile is Mimic
-
The profile start request returned a valid
data.port - Your API token is valid
- Your Puppeteer version is compatible with the current Mimic core
Why does Puppeteer open a different browser?
Make sure your script uses puppeteer.connect() with the port returned by Multilogin rather than launching a separate Puppeteer browser.