问题
- OS: Windows 10 Pro x64-based PC
- node -v: v8.12.0
- npm list puppeteer: `-- puppeteer@1.9.0
I tried this:
puppeteer.launch({
env: {
TZ: 'Australia/Melbourne',
...process.env
}
});
Dont work for me. whoer.net sees my actual systemtime.
EDIT: Some information about https://github.com/nodejs/node/issues/4230
This code works well on Linux but does not work on windows.
process.env.TZ = 'UTC';
console.log(new Date());
On windows i see timezone from my os.
回答1:
To hide that info for all website, you must use combination of different settings. This is not limited to,
- Proxies
- Location
- Timezone
- WebRTC leak
Because every website will have their own method of finding out. Just changing timezone does not mean the website will think you are from somewhere else.
However, the following code worked perfectly for me.
const puppeteer = require('puppeteer');
async function timeZoneChecker({ timeZone }) {
// all kind of config to pass to browser
const launchConfig = {};
if (timeZone) {
launchConfig.env = {
TZ: timeZone,
...process.env,
};
}
const browser = await puppeteer.launch(launchConfig);
const page = await browser.newPage();
await page.goto('https://whoer.net/');
const detectedTimezone = await page.$eval('.ico-timesystem', e => e.parentNode.innerText);
await page.screenshot({ path: `screenshots/timeZone_${timeZone.replace('/', '-')}.png`, fullPage: true });
await browser.close();
return { timeZone, detectedTimezone };
}
Promise.all([
timeZoneChecker({ timeZone: 'Australia/Melbourne' }),
timeZoneChecker({ timeZone: 'Asia/Singapore' }),
]).then(console.log);
Result:
➜ change-timezone node app/timezone.js
[ { timeZone: 'Australia/Melbourne',
detectedTimezone: 'Sun Oct 28 2018 22:44:35 GMT+1100 (Australian Eastern Daylight Time)' },
{ timeZone: 'Asia/Singapore',
detectedTimezone: 'Sun Oct 28 2018 19:44:36 GMT+0800 (Singapore Standard Time)' } ]
来源:https://stackoverflow.com/questions/53027538/how-to-set-change-or-block-timezonesystemtime-with-puppeteer