Problem
withLocale() exists on PendingAwaitablePage (per-visit level):
$page = visit('/')->withLocale('fr-FR');
But there is no equivalent on the global pest()->browser() configuration (Configuration class). The default locale is hardcoded to en-US in PendingAwaitablePage::buildAwaitablePage():
$context = $browser->newContext([
'locale' => 'en-US',
// ...
...$options,
]);
This means every visit() call defaults to en-US for navigator.language, and there's no way to change this globally without passing ['locale' => 'fr'] to every single visit() call.
Use case
Applications that detect the browser language via navigator.language to set the UI language need the Playwright browser context to use the correct locale. With 60+ test files and 179 visit() calls, passing the locale to each one is not practical.
Desired behavior
// tests/Pest.php
pest()->browser()->withLocale('fr');
Similar to how withHost(), userAgent(), timeout(), inDarkMode() etc. already work on Configuration.
Suggested implementation
- Add
Playwright::setDefaultLocale(string $locale) and Playwright::defaultLocale() (similar to existing setHost/host pattern)
- Add
Configuration::withLocale(string $locale) that calls Playwright::setDefaultLocale()
- Use
Playwright::defaultLocale() ?? 'en-US' in PendingAwaitablePage::buildAwaitablePage()
Environment
- pest-plugin-browser: 4.0
- Pest: 4.x
- PHP: 8.5
Problem
withLocale()exists onPendingAwaitablePage(per-visit level):But there is no equivalent on the global
pest()->browser()configuration (Configurationclass). The default locale is hardcoded toen-USinPendingAwaitablePage::buildAwaitablePage():This means every
visit()call defaults toen-USfornavigator.language, and there's no way to change this globally without passing['locale' => 'fr']to every singlevisit()call.Use case
Applications that detect the browser language via
navigator.languageto set the UI language need the Playwright browser context to use the correct locale. With 60+ test files and 179visit()calls, passing the locale to each one is not practical.Desired behavior
Similar to how
withHost(),userAgent(),timeout(),inDarkMode()etc. already work onConfiguration.Suggested implementation
Playwright::setDefaultLocale(string $locale)andPlaywright::defaultLocale()(similar to existingsetHost/hostpattern)Configuration::withLocale(string $locale)that callsPlaywright::setDefaultLocale()Playwright::defaultLocale() ?? 'en-US'inPendingAwaitablePage::buildAwaitablePage()Environment