How To Set, Change Or Block Timezone(systemtime) With Puppeteer?
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.e
Solution 1:
According to the Puppeteer documentation, you can use page.emulateTimezone()
:
page.emulateTimezone()
timezoneId
<?string> Changes the timezone of the page. See ICU’s metaZones.txt for a list of supported timezone IDs. Passingnull
disables timezone emulation.returns: <Promise>
For example:
await page.emulateTimezone('America/Chicago');
Solution 2:
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');
asyncfunctiontimeZoneChecker({ timeZone }) {
// all kind of config to pass to browserconst 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)' } ]
Post a Comment for "How To Set, Change Or Block Timezone(systemtime) With Puppeteer?"