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