UNPKG

puppeteer-extra-plugin-timezone

Version:

A puppeteer-extra plugin to automatically emulate the appropriate timezones using IP reflection services.

77 lines (76 loc) 2.31 kB
import { Browser, Page } from "puppeteer"; import { PuppeteerExtraPlugin } from "puppeteer-extra-plugin"; import { BrowserId, TimezonePluginOptions, TrackedTimezone } from "./types"; /** * Puppeteer Extra Timezone Plugin * * @class * @classdesc Reflects public IP context and adjusts Chrome timezone to match expectation. */ export declare class TimezonePlugin extends PuppeteerExtraPlugin { /** * Tracks the pages resolved by tests. * @type {TrackedTimezone | undefined} */ ctx: Map<BrowserId, TrackedTimezone>; /** * Provide fallbacks if resolution fails. * @type {string} * @protected */ protected _fallbackTz: string | undefined; /** * Constructor * Receives standard puppeteer-extra plugin config options. * * @param {TimezonePluginOptions} opts */ constructor(opts?: TimezonePluginOptions); /** * Describe the identifier for plugin. * @return {string} */ get name(): string; /** * Accessor to previously resolved timezone strings. * @param {BrowserId} browserId * @return {string | undefined} */ getTz(browserId: BrowserId): string | undefined; /** * Upon browser launch, attempt to resolve the timezone, if not already resolved. * * @param {Browser} browser * @return {Promise<void>} */ onBrowser(browser: Browser): Promise<void>; /** * Each new page creation event, emulate the resolved timezone. * * @param {Page} page * @return {Promise<void>} */ onPageCreated(page: Page): Promise<void>; /** * Returns the unique TargetId of a given browser. * * @see https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-getTargetInfo * @param {Browser} browser * @return {Promise<BrowserId>} * @protected */ protected _getBrowserId(browser: Browser): Promise<BrowserId>; /** * Set the fallback value from options or defaults. * * @param {string | string[] | undefined} zones * @protected */ protected _setFallbackTz(zones: string | string[] | undefined): void; } declare const _default: () => TimezonePlugin; /** * Export plugin factory as default export. * @return {TimezonePlugin} */ export default _default;