HTML5 build doesn't load in Electron (DEF-2449)

So, I tried packaging my HTML5 game with Electron and got an error.

After some debugging, I found that Electron has navigator.languages, but it’s an empty array, hence this line in _dmSysGetUserPrefferedLanguage() fails:

var preferred = navigator == undefined ? jsdefault : navigator.languages ? navigator.languages[0] : navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage || jsdefault;

This can be easily fixed by changing the line to:

var preferred = navigator == undefined ? jsdefault : navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage || jsdefault;
4 Likes

Thank you for reporting this. I wonder if this could happen under “normal” circumstances as well (ie in a browser?). Created a ticket: DEF-2449

2 Likes

From https://developer.mozilla.org/en/docs/Web/API/NavigatorLanguage/languages:

[3] In Chrome, navigator.language is the language of the browser UI, and is not guaranteed to be equal to navigator.languages[0].

So, idk, I guess it might happen.

1 Like