Browserless is a cloud-based browser solution designed for effective browser automation, web scraping, and testing.
It utilizes Nstbrowser’s fingerprint library to enable random fingerprint switching, ensuring smooth data collection and automation. Thanks to its robust cloud infrastructure, Browserless simplifies access to multiple browser instances, making it easier to manage automation tasks.
Do you have any wonderful ideas and doubts about web scraping and Browserless?
Let's see what other developers are sharing on Discord and Telegram!
Browserless works by providing a headless browser as a service, which allows users to perform browser automation tasks without the need for a graphical interface.
It enables developers to run browser-based tasks, such as web scraping, automated testing, and rendering web pages, through APIs. By operating in a cloud environment, Browserless simplifies the process of automating browsers by eliminating the need for manual setup or maintaining browser infrastructure.
Browserless supports popular libraries like Puppeteer and Playwright, allowing users to interact with websites programmatically. Its Docker-based infrastructure allows for scalable and flexible deployment, making it efficient for both small-scale and enterprise-level applications. It can be integrated into workflows to automate repetitive tasks or gather data from websites that require a browser to access.
For a better experience, please create a new account on our official website.
Log in to the Nstbrowser client using the information you registered with. After successfully logging in, don't forget to generate your unique API key from the API menu!
You need to get the API Key
and replace the following {YOUR_API_KEY}
part.
docker run -it -e TOKEN={YOUR_API_KEY} -e SERVER_PORT=8848 -p 8848:8848 --name nstbrowserless nstbrowser/browserless:0.0.1-beta
You can connect to the headless browser through Puppeteer, Playwright, Chromedp or other CDP libraries to achieve the operation and screenshot functions of the headless browser.
Puppeteer is a Node.js library that provides a high-level API to control the Chrome browser and supports operations through the DevTools protocol.
npm install puppeteer
puppeteer.js
fileconst puppeteer = require("puppeteer");
(async () => {
const host = "127.0.0.1:8848"; // Replace with your Docker container IP
const browserWSEndpoint = `ws://${host}/ws/connect`;
try {
const browser = await puppeteer.connect({
browserWSEndpoint: browserWSEndpoint,
});
const page = await browser.newPage();
await page.goto("https://google.com", { waitUntil: 'networkidle2' }); // Wait for the network to be idle
await page.screenshot({ path: "screenshot.png", fullPage: true }); // Take a full-page screenshot
console.log("Screenshot taken and saved as screenshot.png");
await browser.close(); // Close the browser connection
} catch (err) {
console.error("Error occurred:", err);
}
})();
node puppeteer.js
After running, you can see that the headless browser is working as we wished:
Now, the project has finished, you can figure out the generated screenshot.png
:
Playwright is a framework for web testing and automation that allows testing the Chrome browser through a single API.
npm install playwright
import { chromium } from "playwright";
(async () => {
const host = "127.0.0.1:8848"; // replace with your Docker container IP
const browserWSEndpoint = `ws://${host}/ws/connect`;
try {
const browser = await chromium.connectOverCDP(browserWSEndpoint);
const context = await browser.newContext();
const page = await context.newPage();
await page.goto("https://www.google.com/", { waitUntil: 'networkidle' }); // wait for the network to be idle
await page.screenshot({ path: "screenshot.png" }); // take a full-page screenshot
console.log("Screenshot taken and saved as screenshot.png");
await browser.close(); // close the browser connection
} catch (err) {
console.error("Error occurred:", err);
}
})();
node playwright.js
Same as Puppeteer, after running, you can figure out the generated screenshot.png
as well.
Browserless makes web scraping and automation easy. In this blog, you can see:
Nstbrowser gives you the optimal solution. Try Browserless for free now!