API Automation in Browsers: What are Selenium, Puppeteer, and Playwright?
Blog » API Automation in Browsers: What are Selenium, Puppeteer, and Playwright?
How to 🔄 automate routine tasks when using an antidetect browser and significantly speed up your workflow? When working with a large number of browser profiles, you often need to perform many simple, repetitive actions. These include tasks like creating a browser profile, adding proxies, bookmarks, filling out registration forms, clicking links, and more. Doing all of this 💪 manually takes a lot of time, especially when managing dozens or even hundreds of profiles.
⚙️ Automation eliminates the need to do everything manually. It speeds up the process many times over, saving time and allowing you to focus on more important tasks. Let’s dive into what browser API automation is and which tools can help you implement it. Let’s go!
What is Browser API Automation? 🤔
It’s the process of managing actions in a browser using 🤖 programmatic commands. In other words, with API automation, you create commands that control operations in the antidetect browser. Programmatic commands execute each operation faster than a human could. They can perform as many actions as needed in the antidetect browser simultaneously. That’s why API automation significantly accelerates the workflow.
Programmatic commands are created in coding environments such as Node.js or Postman. These commands are not only used for actions within the anti-detect browser but also for connecting to it via API. Most people prefer using Postman because it allows for not only writing command codes but also selecting request parameters (e.g., POST or GET). Moreover, Postman offers a richer feature set, including tabs that make writing and testing code more convenient.
Postman Workspace
Automation Tools: Puppeteer, Selenium, and Playwright 🛠️
To create commands, programming libraries such as Puppeteer, Playwright, and Selenium are loaded into the development environment. Let’s briefly go over each one.
Puppeteer ✅
Puppeteer is a library developed by Google for automating actions in the Chrome or Chromium browser using JavaScript. It’s perfect for automating form submissions, generating screenshots and PDF files of web pages, web scraping, and testing web applications. Puppeteer provides a high-level API to control the browser through the DevTools Protocol, enabling nearly any action that a browser user can perform manually.
Playwright ✅
Playwright is a more advanced library developed by Microsoft. It is very similar to Puppeteer but offers additional features. For instance, Playwright allows you to use JavaScript (or TypeScript) to control not only Chromium but also Firefox and WebKit.
Playwright is a powerful API for handling advanced web functionalities such as single-page applications (SPAs), managing web sockets, and working with service workers. It supports device emulation, network interception, and multi-threading, making it a valuable tool for testing, web scraping, and automating tasks in anti-detect browsers.
Selenium ✅
Selenium supports all major web browsers, including Chrome, Firefox, Safari, Internet Explorer, and Edge, making it a popular choice for cross-browser testing. It is also widely used across the industry.
However, when working with modern JavaScript frameworks and libraries, Selenium ☹️ is not as fast or convenient as Puppeteer or Playwright. Additionally, anti-fraud systems have increasingly started to detect browser automation when Selenium is used. This can lead to frequent bans and account freezes, especially in anti-detect workflows.
That said, there’s no need to worry if you’re using 🚀 Dolphin Anty, as it effectively conceals the use of automation tools, including Selenium, ensuring smooth operations without detection.
At one time, Selenium was an indispensable tool for automating web browsers, particularly in web application testing. However, today, it has fallen far behind more advanced libraries.
👉🏻 Experts recommend focusing on the first two tools (Puppeteer and Playwright) because Selenium is outdated in terms of both technical capabilities and performance features.
How Is API Automation Performed? 🙌
API automation in an anti-detect browser consists of three steps ⬇️
- Authorization in the account;
- Connecting an automation library;
- Sending commands to perform actions.
To create and test commands, you need a platform for writing and testing code. In the examples, everything will be done in Postman.
Launching the Anti-Detect Browser and Profile 🪄
To begin, you need to launch the browser through the API with the DevTools protocol enabled. Here’s how:
1. Launch 🔥 Dolphin Anty manually and complete the authorization process. You can log in using either a username and password or a token. For the token option, you’ll need to retrieve it from your personal account on the Dolphin Anty website in the API section.
2. Then, go to Postman and send the following POST request: URL: http://localhost:3001/v1.0/auth/login-with-token
3. Header: Content-Type: application/json
4. Request Body: { “token”: “API_TOKEN” }
👀 In JavaScript, this request would look like this:
👀 Example code in Python:
- Next, replace ‘API_TOKEN’ with your token obtained from the Dolphin Anty website.
- After authorization, start the profile by selecting a GET request and using the following command: http://localhost:3001/v1.0/browser_profiles/PROFILE_ID/start?automation=1
You can also start the profile in headless mode 💻
http://localhost:3001/v1.0/browser_profiles/PROFILE_ID/start?automation=1&headless=1
💡 Headless mode is a mode of operation for a web browser in which it performs all standard functions without a graphical interface. In this mode, the browser loads and interprets web pages, executes JavaScript, and performs all the tasks a regular browser does, but without displaying the interface on the screen. This mode is particularly useful for automating web application testing, web scraping, automated interactions with web pages, and other scenarios where visual representation is unnecessary.
Upon successful profile launch, the response will look something like what’s shown in the screenshot:
Connecting Libraries and Automation 🔗
Now, to set commands for automating actions, you need to connect Puppeteer or Playwright. Once these libraries are connected, you can immediately write commands to execute actions.
✅ For Puppeteer, use the following setup
⬇️
const puppeteer = require(‘puppeteer-core’);
(async () => {
// YOUR port HERE
const port = 50568;
// YOUR wsEndpoint HERE
const wsEndpoint = ‘/devtools/browser/c71c1a9d-f07c-4dd9-84a9-53a4c6df9969’;
// DIRECT CONNECTION
const browser = await puppeteer.connect({
browserWSEndpoint: `ws://127.0.0.1:${port}${wsEndpoint}`
});
// FROM THIS POINT, AUTOMATE WHATEVER YOU WANT
// FOR EXAMPLE, TAKE A SCREENSHOT OF GOOGLE
const page = await browser.newPage();
await page.goto(‘https://google.com’);
await page.screenshot({ path: ‘google.png’ });
await browser.close();
})();
✅ The Playwright library is connected in a similar way:
⬇️
const { chromium } = require(‘playwright’);
(async () => {
// YOUR port HERE
const port = 50568;
// YOUR wsEndpoint HERE
const wsEndpoint = ‘/devtools/browser/c71c1a9d-f07c-4dd9-84a9-53a4c6df9969’;
// DIRECT CONNECTION
const browser = await chromium.connectOverCDP(`ws://127.0.0.1:${port}${wsEndpoint}`);
// FROM THIS POINT, AUTOMATE WHATEVER YOU WANT
// FOR EXAMPLE, TAKE A SCREENSHOT OF GOOGLE
const page = await browser.contexts()[0].newPage();
await page.goto(‘https://google.com’);
await page.screenshot({path: ‘google.png’});
await browser.close();
})();
📚 The full list of automated actions and their code equivalents can be found here: Dolphin Anty Remote API Docs.
List of Actions for Automation in the Left Column.
As we can see, all the typical actions in anti-detect browsers are gathered here. To quickly navigate to the developer environment, there’s a “Run in Postman” button in the top right corner.
Stopping a Profile ❌
To stop a profile after use, send the following GET request: http://localhost:3001/v1.0/browser_profiles/PROFILE_ID/stop.
In Conclusion ✅
To summarize, using API automation tools like Selenium, Puppeteer, and Playwright significantly simplifies the management of multiple accounts. By interacting with the browser and performing various actions on web pages, these tools enable more efficient and reliable workflows, not to mention exponential acceleration. While manually managing 50 profiles a day might be achievable, automation makes it effortless to handle 1,000 or more! 🦾
As a result, productivity increases, allowing you to farm more accounts, upload more products on marketplaces, participate in crypto activities, and perform many other useful tasks. By the way, when working via API, you can combine automation with manual browser management.
🤓 We hope this article serves as your gateway to the world of automation. Also, remember that you can reach out to our friendly support team directly in the Dolphin Anty program chat for any assistance!