Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/plugins/default-browser-emulator/lib/helpers/setTimezone.ts
1030 views
1
import IDevtoolsSession from '@secret-agent/interfaces/IDevtoolsSession';
2
import BrowserEmulator from '../../index';
3
4
export default async function setTimezone(
5
emulator: BrowserEmulator,
6
devtools: IDevtoolsSession,
7
): Promise<void> {
8
const { timezoneId } = emulator;
9
if (!timezoneId) return;
10
try {
11
await devtools.send('Emulation.setTimezoneOverride', { timezoneId });
12
} catch (error) {
13
if (error.message.includes('Timezone override is already in effect')) return;
14
if (error.message.includes('Invalid timezone'))
15
throw new Error(`Invalid timezone ID: ${timezoneId}`);
16
throw error;
17
}
18
}
19
20