Puppeteer emulateTimezone persistence during page navigation
0 reputation · 06 Sept 2021, 15:29 UTC
Timezone Emulation and Date Conversion
Puppeteer provides the page.emulateTimezone(ianaId) method to override the perceived IANA timezone for a page context. This ensures that Date evaluations, such as toLocaleString() and getTimezoneOffset(), return values consistent with the specified region.
There is uncertainty regarding the lifecycle of this override when the browser context changes. Specifically, it is unclear if the timezone setting remains active after a page navigation, a full reload, or the attachment of new frames, or if the browser reverts to the system default timezone.
When testing date-sensitive logic across multiple pages, maintaining a stable offset is critical to avoid mixed timezone contexts.
- Does
page.emulateTimezonepersist acrosspage.goto()orpage.reload()calls? - Is re-application of the timezone override required after each navigation to guarantee consistent
Date.now()behavior?