/
proxy.js
26 lines (20 loc) · 863 Bytes
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// require('dotenv').config();
// Replace this import with `require('..')` if you are running the example from the repository:
const { plugin } = require('puppeteer-with-fingerprints');
// The default proxy value is just an example, it won't work.
const proxy = process.env.FINGERPRINT_PROXY ?? 'socks5://127.0.0.1:9762';
(async () => {
plugin.useProxy(proxy, {
detectExternalIP: false,
changeGeolocation: true,
});
const browser = await plugin.launch({
// This argument will be ignored if the `useProxy` method has been called.
args: [`--proxy-server=${proxy}`],
});
const page = await browser.newPage();
await page.goto('https://canhazip.com/', { waitUntil: 'domcontentloaded' });
const result = await page.evaluate(() => document.body.innerText.trim());
console.log('External IP:', result);
await browser.close();
})();