Skip to main content
Playwright

How to setup Playwright with NodeMaven Proxies and IP Whitelisting

Cornel avatar
Written by Cornel
Updated over a month ago

Playwright is a versatile Node.js library for automating web browsers, supporting tasks like UI testing, web scraping, form submissions, and page interactions. It works with Chromium, Firefox, and WebKit browsers. Playwright supports JavaScript, TypeScript, Python, and C#, making it a powerful tool for developers and testers across different languages and use cases.

For more information on Playwright please visit their official website:

Setup

Before anything, check if Node.js is installed: Open a terminal (Command Prompt or shell) and type the following command:

node -v

If you get a version number, Node.js is already installed. The version number will look like this:

In this case go to: Step 2: Install Playwright

If Node.js is not installed on your system you will get this error:

'node' is not recognized as an internal or external command

If this is your case continue with the steps below:

Step 1: Install Node.js

  1. Download Node.js:

2. Install Node.js:

  • Run the installer you downloaded.

  • Follow the installation wizard.

Step 2: Install Playwright

  1. Install Playwright globally by running the following command:

npm init playwright@latest

2. Follow the prompts to configure the project, and ensure browsers are installed when prompted.

This is an example but you can make your own choices:

  • After Playwright is installed you should get the following message:

Step 3: Create a project directory

  1. Create a directory for your project and go to that location:

mkdir playwright_nodemaven_project 

cd playwright_nodemaven_project

2. Create and navigate to the subdirectory for scripts:

mkdir src
cd src

Step 4: Set Up Playwright with a NodeMaven Proxy

Create a new file, playwright_ip_whitelist.js in your src directory. Use your preferred text editor.

  • Add the following code to playwright_ip_whitelist.js:

const { chromium } = require('playwright');

(async () => {
const proxy = 'http://gate.nodemaven.com:8080'; // Replace with your proxy URL

// Launch the browser with proxy settings
const browser = await chromium.launch({
proxy: { server: proxy },
});

const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://nodemaven.com/');
console.log('Page title:', await page.title());

await browser.close();
})();

Step 5: Run Your Script

  • Open Command Prompt and navigate to the src directory and then run the following command:

node playwright_ip_whitelist.js

Expected output:

  • The Command Prompt will print the page title:

Now you are ready to personalize your script and start using Playwright with NodeMaven proxies!

Did this answer your question?