I am fairly new to JavaScript and recently installed UAParser-JS from https://github.com/faisalman/ua-parser-js into my ReactJS project and am trying to figure out how to properly get the CPU architecture (ex: "amd64") from my computer to display in the console of my application.
"ua-parser-js": "^0.7.20" is showing in my package.json, so it seems to have been installed properly. I have looked at the example their github repo and played around with the code a lot, unsuccessfully so far. Unfortunately, I can not seem to find any other examples online. They appear to have a tag with a {{src="ua-parser.min.js"}} and am not sure if this is playing a role in being unsuccessful.
This is top portion of the code from their site and you can see the CPU-Architecture is printed at the bottom.
<!doctype html>
<html>
<head>
<script type="text/javascript" src="ua-parser.min.js"></script>
<script type="text/javascript">
var parser = new UAParser();
// by default it takes ua string from current browser's //window.navigator.userAgent
console.log(parser.getResult());
/*
/// this will print an object structured like this:
{
ua: "",
browser: {
name: "",
version: ""
},
engine: {
name: "",
version: ""
},
os: {
name: "",
version: ""
},
device: {
model: "",
type: "",
vendor: ""
},
cpu: {
architecture: ""
}
}
*/
// let's test a custom user-agent string as an example
var uastring = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2";
parser.setUA(uastring);
var result = parser.getResult();
// this will also produce the same result (without instantiation):
// var result = UAParser(uastring);
console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
console.log(result.os); // {name: "Ubuntu", version: "11.10"}
console.log(result.os.version); // "11.10"
console.log(result.engine.name); // "WebKit"
console.log(result.cpu.architecture); // "amd64"
In it's simplest form, I get "UAParser" is undefined and don't understand what I am doing differently than the example on the github page.
let parser = new UAParser();
console.log(parser.getResult());
I expect to see my CPU-architecture but "UAParser" is undefined.