Confusion about js.html.Navigator

If I import js.html.Navigator and then try to access Navigator.language, the compiler reports “Class<js.html.Navigator> has no field languages” even while the docs say it’s there. js.html.Window.navigator has the same problem.

Thankfully if I use js.Browser.navigator (which returns a reference to it works fine, probably because global is a Dynamic.

Is that a bug or a feature I’m not understanding?

language is an instance field. You can’t access instance fields as statics.

So the docs for js.Browser.navigator say it is a shortcut to Window.navigator, but inspecting the code that description doesn’t really seem accurate. I would expect those to be interchangeable when coding based on the docs.

Actually, navigator is set to the window, so these both work:

trace(js.Browser.window.navigator.language); // en-US
trace(js.Browser.navigator.language); // en-US

Edit;whoops sorry replying to a 20 days old thread

1 Like