Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/plugins/default-browser-emulator/lib/helpers/setLocale.ts
1030 views
1
import IDevtoolsSession from '@secret-agent/interfaces/IDevtoolsSession';
2
import BrowserEmulator from '../../index';
3
4
export default async function setLocale(
5
emulator: BrowserEmulator,
6
devtools: IDevtoolsSession,
7
): Promise<void> {
8
const { locale } = emulator;
9
if (!locale) return;
10
try {
11
await devtools.send('Emulation.setLocaleOverride', { locale });
12
} catch (error) {
13
// not installed in Chrome 80
14
if (error.message.includes("'Emulation.setLocaleOverride' wasn't found")) return;
15
// All pages in the same renderer share locale. All such pages belong to the same
16
// context and if locale is overridden for one of them its value is the same as
17
// we are trying to set so it's not a problem.
18
if (error.message.includes('Another locale override is already in effect')) return;
19
throw error;
20
}
21
}
22
23