Puppeteer - setOfflineMode() disconnects proxy connection if "headless" is false
Reported by
baldinie...@gmail.com,
Oct 23
|
|
Issue description
Chrome Version : Version 71.0.3563.0 (Developer Build) (64-bit)
URLs (if applicable) :
Other browsers tested:
Using the script at the end of the page I see that `headless: false` causes Chrome to disconnect from the proxy at `page.setOfflineMode(true)`, while Chrome remains connected to the proxy if `headless: true`. The relevancy of this inconsistency is due to automatic IP address rotation whenever a new connection is established toward the proxy.
The script can run as-is; a valid proxy argument is required.
----
const puppeteer = require("puppeteer");
let browser, page;
async function openBrowser() {
browser = await puppeteer.launch({
args: [ `--proxy-server=http://localhost:${proxyPort}` ],
headless: false,
defaultViewport: { width: 1024, height: 768 }
});
}
async function openPage() {
page = await browser.newPage();
await page.setUserAgent("Mozilla/5.0 (X11; Linux i686; rv:59.0) Gecko/20100101 Firefox/59.0");
await page.setDefaultNavigationTimeout(latencyMs);
await page.setExtraHTTPHeaders({'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8'});
}
async function checkAddress(page) {
let pageText = "",
url = "http://whatismyip.akamai.com/";
await page.goto(url, { waitUntil: "load" });
pageText = await page.evaluate(() => document.body.innerText);
console.log(pageText);
}
await openBrowser();
while (true) {
await openPage();
await checkAddress(page);
await page.setOfflineMode(true);
await page.setOfflineMode(false);
await page.close();
}
|
|
►
Sign in to add a comment |
|