Skip to content
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

navigator.languages returns an empty array #11053

Closed
kysely opened this issue Nov 7, 2017 · 10 comments
Closed

navigator.languages returns an empty array #11053

kysely opened this issue Nov 7, 2017 · 10 comments

Comments

@kysely
Copy link

kysely commented Nov 7, 2017

  • Electron version: 1.7.9
  • Operating system: macOS

Expected behavior

navigator.languages should return array of user's preferred languages, e.g. ["en-US", "zh-CN", "ja-JP"]

Actual behavior

navigator.languages returns an empty array []

How to reproduce

Create a primitive HTML file that logs navigator.languages into console. Then try loading via file://, http and inside Electron's renderer process. The first two will give you actual results while renderer yields empty array.

@welcome
Copy link

welcome bot commented Nov 7, 2017

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@kysely
Copy link
Author

kysely commented Nov 7, 2017

Okay, so you can set the navigator.languages to your own custom value in preload, but this is still just a workaround.

To obtain actual user locale settings during preload, use os-locale module. Make sure sandbox is disabled on the window.

Object.defineProperty(navigator, 'languages', {
    value: ["en-US", "zh-CN", "ja-JP"],
    configurable: true
});

@felixrieseberg
Copy link
Member

Yep, that's a legit bug (or at least a documentation issue).

@melvin-clickprofits
Copy link

Hi i'm kinda stuck on this issue, i have implemented skype https://dev.skype.com/webcontrol on web page, but i got an error on their js library due to a bad checking of the navigator.languages

screenshot at 2017-11-10 10 47 29

is there any work around to set default value for navigator.languages ?

main issue is the skype sdk loaded by an iframe injected by the sdk, so even i set it in my page, it will no work.

Thanks in advance.

@kysely
Copy link
Author

kysely commented Nov 10, 2017

@melvin-clickprofits Did you try the solution I propose above? It works for me.

If you need to set navigator.languages for the iframed document, you can do it the same way, only instead navigator object, you'd need to pass the iframe document's navigator, like this:

Object.defineProperty(document.querySelector("#iframeId").contentWindow.navigator, 'languages', {
    value: ["en-US", "zh-CN", "ja-JP"], // or whatever you want
    configurable: true
});

And of course, you'd need to set the iframe navigator on its parent page, not during BrowserWindow preload.

@melvin-clickprofits
Copy link

melvin-clickprofits commented Nov 10, 2017

@kysely tested it works, ju Thanks 👍, just have to make sure the iframe is already inserted

@haoRchen
Copy link

Hi, I'd love to tackle this if no one is working on it.

@nitsakh
Copy link
Contributor

nitsakh commented Feb 23, 2018

I'm working on it currently.

@tonyganch
Copy link
Contributor

@ckerr, can this issue be closed? I see PR merged.

@nornagon
Copy link
Member

nornagon commented Aug 3, 2018

Looks fixed to me!

@nornagon nornagon closed this as completed Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants