mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Fix #489: ARM arch detection & create test that simulates HTTP headers sent from an Apple silicon
This commit is contained in:
parent
3af8e1e272
commit
e70d09a1f8
@ -1056,7 +1056,7 @@
|
||||
var archName = uaCH[ARCHITECTURE];
|
||||
if (archName) {
|
||||
if (archName && uaCH[BITNESS] == '64') archName += '64';
|
||||
rgxMapper.call(this.data, archName, rgxMap);
|
||||
rgxMapper.call(this.data, archName + ';', rgxMap);
|
||||
}
|
||||
break;
|
||||
case UA_DEVICE:
|
||||
|
30
test/test.js
30
test/test.js
@ -483,6 +483,36 @@ describe('Map UA-CH headers', function () {
|
||||
assert.strictEqual(uap.os.name, "Linux");
|
||||
assert.strictEqual(uap.os.version, "x86_64");
|
||||
});
|
||||
|
||||
it('Can detect Apple silicon from client hints data', function () {
|
||||
|
||||
// https://github.com/faisalman/ua-parser-js/issues/489#issuecomment-1479213579
|
||||
const httpHeadersFromAppleSilicon = {
|
||||
'sec-ch-ua-arch' : 'arm',
|
||||
'sec-ch-ua-platform' : 'macOS',
|
||||
'sec-ch-ua-mobile' : '?0',
|
||||
'sec-ch-ua' : '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
|
||||
'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:97.0) Gecko/20100101 Firefox/97.0'
|
||||
};
|
||||
|
||||
UAParser(httpHeadersFromAppleSilicon).withClientHints().then(function (ua) {
|
||||
|
||||
// Only works in Chrome
|
||||
/*
|
||||
if (ua.os.is("macOS") &&
|
||||
ua.cpu.is("arm") &&
|
||||
!ua.device.is("mobile") &&
|
||||
!ua.device.is("tablet")) {
|
||||
// possibly an Apple silicon device
|
||||
}
|
||||
*/
|
||||
|
||||
assert.strictEqual(ua.os.is("macOS"), true);
|
||||
assert.strictEqual(ua.cpu.is("arm"), true);
|
||||
assert.strictEqual(ua.device.is("mobile"), false);
|
||||
assert.strictEqual(ua.device.is("tablet"), false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Map UA-CH JS', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user