Puppeteer
This guide provides instructions on how to integrate Evomi’s proxies with Puppeteer, a Node.js library for controlling headless Chrome or Chromium.
Prerequisites
Before you begin, ensure you have the following:
- Node.js installed on your system
- Puppeteer installed in your project
- Your Evomi proxy credentials (username and password)
Installation
If you haven’t already installed Puppeteer, you can do so using npm:
npm install puppeteer
Configuration
To use Evomi proxies with Puppeteer, you need to configure the browser launch options with the proxy settings. Here’s how you can do it:
const puppeteer = require('puppeteer');
(async () => {
const proxyServer = 'http://rp.evomi.com:1000';
const username = 'your_username';
const password = 'your_password_session-anychars_mode-speed';
const browser = await puppeteer.launch({
args: [
`--proxy-server=${proxyServer}`,
],
});
const page = await browser.newPage();
// Set up authentication
await page.authenticate({
username: username,
password: password,
});
await page.goto('https://ip.evomi.com/s');
const content = await page.content();
console.log(content);
await browser.close();
})();
Replace your_username
with your actual Evomi proxy username.
Explanation
Let’s break down the key parts of this script:
- We import the Puppeteer library.
- We set up the proxy configuration with the Evomi proxy details.
- We launch a new browser instance with the proxy server argument.
- We create a new page and set up proxy authentication using the
authenticate
method. - We navigate to
https://ip.evomi.com/s
to verify the proxy connection. - We print the page content, which should show the IP address of the proxy you’re using.
- Finally, we close the browser.
Evomi Proxy Endpoints
Depending on the Evomi product you’re using, you’ll need to adjust the proxy server address in your code. Here are the endpoints for different Evomi products:
Residential Proxies
- HTTP Proxy: rp.evomi.com:1000
- HTTPs Proxy: rp.evomi.com:1001
- SOCKS5 Proxy: rp.evomi.com:1002
Mobile Proxies
- HTTP Proxy: mp.evomi.com:3000
- HTTPs Proxy: mp.evomi.com:3001
- SOCKS5 Proxy: mp.evomi.com:3002
Datacenter Proxies
- HTTP Proxy: dcp.evomi.com:2000
- HTTPs Proxy: dcp.evomi.com:2001
- SOCKS5 Proxy: dcp.evomi.com:2002
To use a different product or protocol, simply replace the proxyServer
variable in your code with the appropriate endpoint and port from the list above.
Running the Script
Save the script to a file (e.g., puppeteer_proxy_test.js
) and run it using Node.js:
node puppeteer_proxy_test.js
If everything is set up correctly, you should see the content of https://ip.evomi.com/s
printed in your console, showing the IP address of the Evomi proxy you’re using.
Tips and Troubleshooting
- If you’re having connection issues, double-check your proxy credentials and make sure you’re using the correct endpoint and port for your chosen product.
- The proxy password format (
your_password_session-anychars_mode-speed
) includes additional parameters. Make sure to replaceyour_password
with your actual password while keeping thesession-anychars_mode-speed
part intact. - For HTTPS connections, you might need to handle SSL certificate errors. You can add the following option to ignore SSL errors (use with caution in production):
const browser = await puppeteer.launch({ args: [ `--proxy-server=${proxyServer}`, '--ignore-certificate-errors', ], });
- If you need to use a SOCKS5 proxy, you’ll need to install an additional package:
Then modify your script to use it:
npm install proxy-chain
const proxyChain = require('proxy-chain'); const oldProxyUrl = `socks5://${username}:${password}@rp.evomi.com:1002`; const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl); const browser = await puppeteer.launch({ args: [`--proxy-server=${newProxyUrl}`], });
- Remember to handle errors appropriately in your production code, as network requests can fail for various reasons.
By following this guide, you should now be able to successfully integrate Evomi’s proxies with your Puppeteer scripts for web automation and scraping tasks.