Puppeteer (Node.js)
Introduction
This guide provides a step-by-step example of how to connect to a remote browser using the Puppeteer library for Node.js. It includes instructions on how to use an API token for authentication when connecting to CloudBrowser.
Prerequisites
Node.js: Ensure Node.js is installed on your system.
CloudBrowserConnector Library: Install Puppeteer by running
npm install cloud-browser-connector
.API Token: Your unique API token for authenticating requests to CloudBrowser.
Example Code
The following code demonstrates how to connect to a remote browser using Puppeteer, retrieve the WebSocket endpoint with an API token, and perform basic navigation.
In summary, this code:
Connects to a remote browser using CloudBrowser.
Opens a new page in that browser session.
Then navigates to a given URL.
Ensure the browser is closed after operations are complete.
Error Handling
HTTP Request Errors: Handle errors when fetching the WebSocket URL by checking the response status and throwing an error if the request fails.
Connection Errors: Catch and log errors that occur during connection to the remote browser or during navigation.
Last updated