Can you advice me how to get Navigator.oscpu using Scala-js? Mapping to native Navigator does not seems to have the oscpu. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/oscpu
Asked
Active
Viewed 134 times
1 Answers
1
This appears to be a Firefox-only feature (based on a quick look around), so it's not supported by Scala.js out of the box. You'll need to add it yourself, by adding a side-facade to Navigator. This isn't terribly hard -- see the definition of BeaconNavigator for an example of how to do this.
So you would need something like (untested):
@js.native
trait OSCPUNavigator extends js.Object {
def oscpu: String = js.native
}
implicit def toOSCPUNavigator(n: Navigator): OSCPUNavigator =
n.asInstanceOf[OSCPUNavigator]
Basically, you define a trait with oscpu
on it, and you tell Scala.js how to see a Navigator
as that trait.
Mind, though, it'll still only work on Firefox. I suspect it'll throw errors on other browsers...

Justin du Coeur
- 2,699
- 1
- 14
- 19
-
You are right. It works on Firefox only. A simple mapping like this works @native trait Navigator extends Object { val oscpu:String } – Skoky May 24 '16 at 15:48