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).
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();
}
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With