Skip to content

Device.getLanguageCode() hangs when used inside Playwright #2375

@ViMaSter

Description

@ViMaSter

Bug Report

Plugin(s)

  • @capacitor/device: 7.0.1

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 7.2.0
  @capacitor/core: 7.2.0
  @capacitor/android: 7.2.0
  @capacitor/ios: 7.2.0

Installed Dependencies:

  @capacitor/cli: 7.2.0
  @capacitor/android: 7.2.0
  @capacitor/ios: 7.2.0
  @capacitor/core: 7.2.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

  • Ubuntu 24.04.2 LTS (via GitHub Actions)
  • macOS Sonoma 14.6.1 (23G93) (locally)

Current Behavior

  1. Integration tests using Playwright that encounter await Device.getLanguageCode() hang and time out; there's no log output in the browser spawned by Playwright, nor in the Playwright logs
  2. Using the same browser version by hand to access the web server created by vite --host works, and the plugin returns the language code of navigator.language

Expected Behavior

  1. Integration tests using Playwright that encounter await Device.getLanguageCode() receive the language code of navigator.language
  2. Using the same browser version by hand to access the web server created by vite --host works, and the plugin returns the language code of navigator.language

Code Reproduction

  1. Clone this branch of the affected project
  2. Run nvm install && nvm use && npm install
  3. Run npm run test:e2e
  4. Notice browsers opening an empty page, which stays for 60 seconds, after which the test times out and fails
  5. Comment out the call to await Device.getLanguageCode() by commenting out lines 27 and 28 of /src/main.ts
  6. Notice browsers loading the app and tests succeeding after ~30 seconds

Other Technical Details

Reproducible using GitHub Actions: https://github.com/ViMaSter/gdqreminder-mobile/actions/runs/15228335975/job/42833119806#step:6:47

Replacing the call to Device.getLanguageCode() with a function with the same content works:

const getLocale = async () => {
  return {value: navigator.language.split('-')[0].toLowerCase()};
};
console.log(await getLocale()); // returns `en`
console.log((await Device.getLanguageCode()).value); // hangs

However, this skips the native methods implemented by the plugin on iOS and Android, making this a suboptimal workaround.

Additional Context

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions