Skip to content

Using locale_code does not change the local date format #3787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Abdelgha-4 opened this issue Jun 1, 2025 · 1 comment · Fixed by #3792
Closed

Using locale_code does not change the local date format #3787

Abdelgha-4 opened this issue Jun 1, 2025 · 1 comment · Fixed by #3792
Assignees
Labels
bug Uh oh... Something needs to be fixed UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@Abdelgha-4
Copy link

Using:

from seleniumbase import SB

with SB(uc=True, incognito=True, locale_code="en_us") as sb:
    # Set timezone and geolocation
    sb.activate_cdp_mode("https://www.example.com", tzone="America/New_York", geoloc=(40.7128, -74.0060))

    # Now test JavaScript date formatting
    date_str = sb.execute_script("return new Date(2025, 5, 24).toLocaleDateString();")
    locale = sb.execute_script("return Intl.DateTimeFormat().resolvedOptions().locale;")
    print(f"Formatted date: {date_str}")
    print(f"Resolved JS locale: {locale}")

Outputs:

Formatted date: 24/06/2025
Resolved JS locale: fr

However using:

from seleniumbase import SB

with SB(uc=True, incognito=True) as sb:
    # Set timezone and geolocation
    sb.activate_cdp_mode("https://www.example.com", tzone="America/New_York", geoloc=(40.7128, -74.0060))

    # Force JavaScript locale override using CDP
    sb.execute_cdp_cmd("Emulation.setLocaleOverride", {"locale": "en-US"})

    # Now test JavaScript date formatting
    date_str = sb.execute_script("return new Date(2025, 5, 24).toLocaleDateString();")
    locale = sb.execute_script("return Intl.DateTimeFormat().resolvedOptions().locale;")
    print(f"Formatted date: {date_str}")
    print(f"Resolved JS locale: {locale}")

Correctly outputs:

Formatted date: 6/24/2025
Resolved JS locale: en-US

Used version: 4.39.1

@mdmintz mdmintz self-assigned this Jun 3, 2025
@mdmintz mdmintz added bug Uh oh... Something needs to be fixed UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Jun 3, 2025
@mdmintz
Copy link
Member

mdmintz commented Jun 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh oh... Something needs to be fixed UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants