3

I have a Puppeteer app running on a Windows Server. That server's IP address is blocked by some of the sites it has been crawling, so it needs a new one. I have a NordVPN account but have been informed via Server Fault that if I were to run the NordVPN app that I would lose remote desktop access at its static IP (https://serverfault.com/questions/1060082/would-adding-nordvpn-to-a-windows-server-block-remote-access-at-its-ip/1060085) and I believe that websites whose DNS is pointing at that IP would not be accessible either, so I need a different solution.

I have found a few examples of using Puppeteer to connect to a VPN, but those solution appear to use or Linux servers (How to connect VPN using nodejs in ubuntu).

2 Answers2

6

Try this... it does not rely on any other modules... Change the user/pass to you service ones in your account and change the vpnServer to whatever one you want to use.

#!/usr/bin/env node

// Screengrab generator
// outputs a JSON object with a base64 encoded image of the screengrab
// eg;

const puppeteer = require('puppeteer');

let conf = new Object();

conf.url = "https://www.telegraph.co.uk";

// VPN
conf.vpnUser   = conf.vpnUSer   || 'USERNAME';
conf.vpnPass   = conf.vpnPass   || 'PASSWORD';
conf.vpnServer = conf.vpnServer || "https://uk1785.nordvpn.com:89";

(async() => {
    const browser = await puppeteer.launch({
        headless: true,
        args: [
            '--disable-dev-shm-usage',
            '--proxy-server='+conf.vpnServer
        ]
    });

    try {
        const page = await browser.newPage();

        await page.authenticate({
            username: conf.vpnUser,
            password: conf.vpnPass,
        });

        await page.goto(conf.url, { waitUntil: 'networkidle2' });
    } catch (error) {
        console.error(error);
    } finally {
        await browser.close();
    }
})();
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Sean Dillon
  • 81
  • 1
  • 3
0

The best way to not get blocked is to use the proxy Option of puppeteer. Proxy Puppeteer Tutorial

Ethanolle
  • 1,106
  • 1
  • 8
  • 26
  • Thanks, I have been trying the Zyte 14 day trial but their staff says you need to use Crawlera if you are using Puppeteer > 1.17 and I am using 8.0.0. Unfortunately, I cannot find instructions for how to install Crawlera on Windows Server. – WannabePuppetMaster Apr 13 '21 at 05:48