Add withLocale() to global browser configuration
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 11.7k
- Forks
- 538
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Description
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)andPlaywright::defaultLocale()(similar to existingsetHost/hostpattern) - Add
Configuration::withLocale(string $locale)that callsPlaywright::setDefaultLocale() - Use
Playwright::defaultLocale() ?? 'en-US'inPendingAwaitablePage::buildAwaitablePage()
Environment
- pest-plugin-browser: 4.0
- Pest: 4.x
- PHP: 8.5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing setHost/host pattern in Playwright and Configuration, then inspect PendingAwaitablePage::buildAwaitablePage() where the browser context locale defaults to en-US. Add the global locale behavior described in the issue and verify that visit() uses it for navigator.language while retaining en-US when no locale is configured.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, playwright
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100