{"record":{"id":"2eea06e563e45ea1","repo":"grafana/k6","slug":"emulating-locale-q-w","errorCode":null,"errorMessage":"emulating locale %q: %w","messagePattern":"emulating locale %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":202,"sourceCode":"\tif err = fs.initDomains(); err != nil {\n\t\tl.Debugf(\n\t\t\t\"NewFrameSession:initDomains\",\n\t\t\t\"sid:%v tid:%v err:%v\",\n\t\t\ts.ID(), tid, err)\n\n\t\treturn nil, err\n\t}\n\n\treturn &fs, nil\n}\n\nfunc (fs *FrameSession) emulateLocale() error {\n\taction := emulation.SetLocaleOverride().WithLocale(fs.page.browserCtx.opts.Locale)\n\tif err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\tif strings.Contains(err.Error(), \"Another locale override is already in effect\") {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"emulating locale %q: %w\", fs.page.browserCtx.opts.Locale, err)\n\t}\n\treturn nil\n}\n\nfunc (fs *FrameSession) emulateTimezone() error {\n\taction := emulation.SetTimezoneOverride(fs.page.browserCtx.opts.TimezoneID)\n\tif err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\tif strings.Contains(err.Error(), \"Timezone override is already in effect\") {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"emulating timezone %q: %w\", fs.page.browserCtx.opts.TimezoneID, err)\n\t}\n\treturn nil\n}\n\nfunc (fs *FrameSession) getNetworkManager() *NetworkManager {\n\treturn fs.networkManager\n}","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L184-L220","documentation":"FrameSession.emulateLocale (frame_session.go:202) sends Emulation.setLocaleOverride with the `locale` browser-context option. Chromium rejects malformed/unsupported locale strings (other than the 'already in effect' error, which is swallowed), and the failure is wrapped with the offending locale. The error surfaces during page/session initialization, so the page never opens.","triggerScenarios":"browser.newContext({ locale: 'xx-XX' }) or a locale Chromium does not recognize (e.g. 'en_US' with an underscore, empty string passed explicitly, or free-text like 'english'). Locale comes from the context options and is applied per frame session.","commonSituations":"Underscore vs hyphen confusion (ICU/Java style 'en_US' instead of BCP-47 'en-US'), locales valid on the developer's OS but not compiled into the bundled chromium build, or values coming from config without validation.","solutions":["Use a BCP-47 locale with a hyphen, e.g. 'en-US', 'fr-FR', 'de-DE'","Verify the locale is supported by chromium/ICU before passing it (see validation snippet)","If you do not actually need locale emulation, omit the option entirely"],"exampleFix":"// before\nconst ctx = browser.newContext({ locale: 'en_US' });\n\n// after\nconst ctx = browser.newContext({ locale: 'en-US' });","handlingStrategy":"validation","validationCode":"function validLocale(l) {\n  if (!l) return l;\n  if (!/^[a-z]{2,3}(-[A-Z]{2}|-[0-9A-Za-z]+)*$/i.test(l)) {\n    throw new Error(`locale looks invalid (use BCP-47 like 'en-US'): ${l}`);\n  }\n  return l;\n}\nbrowser.newContext({ locale: validLocale(cfg.locale) });","typeGuard":"function isBcp47Locale(v: unknown): v is string {\n  return typeof v === 'string' && /^[a-z]{2,3}(-[A-Z][a-z]{3})?(-([A-Z]{2}|\\d{3}))?$/i.test(v);\n}","tryCatchPattern":null,"preventionTips":["Use hyphens, never underscores: 'en-US' not 'en_US'","Omit locale entirely when emulation is not required"],"tags":["browser","locale","emulation","context-options","i18n"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}