Puppeteer is a commonly used browser automation tool that can be useful for accessing and processing web pages programatically. In this guide, we'll walk you step-by-step through connecting Puppeteer with Nimble IP used Node.js.
This guide assumes you have already installed Puppeteer and Node.js on the relevant computer/server.
To use Puppeteer with Nimble IP, first install the proxy-chain extension.
npminstallpuppeteerproxy-chain
With proxy-chain installed, we can now build our main script:
constpuppeteer=require('puppeteer');constproxyChain=require('proxy-chain');(async () => {constoldProxyUrl='http://account-accountName-pipeline-pipelineName:[email protected]:7000'; // Replace with your Nimble Pipeline proxy credentialsconstnewProxyUrl=awaitproxyChain.anonymizeProxy(oldProxyUrl);constbrowser=awaitpuppeteer.launch({ args: ['--no-sandbox','--disable-setuid-sandbox',`--proxy-server=${newProxyUrl}`,// Use the new anonymized proxy URL ], });constpage=awaitbrowser.newPage();awaitpage.goto('https://example.com'); // Replace with your target URLconsole.log('Page loaded');// Add any actions you want to perform on the page here// Close the anonymized proxy serverawaitproxyChain.closeAnonymizedProxy(newProxyUrl,true);awaitbrowser.close();})();
Explanation:
Anonymize the Proxy URL: The proxyChain.anonymizeProxy(oldProxyUrl) function takes your proxy URL (which includes the username and password for authentication) and creates a new anonymized proxy URL. This URL will be used by Puppeteer to route its requests.
Use the New Proxy URL in Puppeteer: The new proxy URL is passed as an argument to Puppeteer's launch method. This lets Puppeteer connect through the proxy without needing to handle the authentication headers manually.
Clean Up: After your browsing is done, it’s good practice to close the anonymized proxy server using proxyChain.closeAnonymizedProxy(newProxyUrl, true), which ensures that the server is not left running unnecessarily.
This method effectively integrates Nimble IP seamlessly with Puppeteer, allowing for all the benefits of Nimble IP to be used in conjunction with existing Puppeteer-based workflows.
If you're interested in upgrade to a modern data Browser, we recommend seeing Nimble Unlocker Proxy.