ua-parser-js
ua-parser-js copied to clipboard
iPad Air and iPad Pro - type not correctly identified
Library version v1.0.37
Describe the bug iPad Pro and iPad Air user agents from Chrome Dev Tools are not recognized as tablets. Mentioning Chrome Dev Tools here as I can't rule out Chrome using incorrect user agents.
To Reproduce Steps to reproduce the behavior:
- Open Chrome Dev Tools --> Device Toolbar
- Select iPad Air or iPad Pro from list
- Visit webpage that uses ua-parser-js
deviceis returned as{ vendor: 'Apple', model: 'Macintosh', type: undefined }
Alternatively use one of these user agents which is what my Chrome (Version 119.0.6045.124) is using:
- iPad Air -
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15 - iPad Pro -
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15
Expected behavior
device returned as { vendor: 'Apple', model: 'iPad', type: 'tablet' }
If you use getOS function through the ipads, what is returned inside { name } of both of them?
Hi @rickson-simoes, in both cases I get {name: 'Mac OS', version: '10.15.7'} with the getOS function. I guess this should be iOS instead. Selecting "IPad Mini" in the browser returns {name: 'iOS', version: '16.6'} for example.
I am facing same issue, it cannot detect Ipad with latest iOS 17, i am getting - { vendor: 'Apple', model: 'Macintosh', type: undefined }. Apple updated userAgent for iPad - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1.1 Safari/604.1 - this from real iPad Safari using latest iOS 17. So there is no iPad anymore in useragent. Has anyone found how to detect iPad ?
Since Apple froze its user agent in version 10.15.7, we haven't yet find a reliable solution that can be derived from only the user agent data (as in the Chrome Dev Tools case). However, if we are using a real browser in iPad we can try to do an additional check for iPad-specific browser features:
const uap = new UAParser();
const device1 = uap.getDevice();
const device2 = uap.getDevice().withFeatureCheck();
console.log(device1); // { vendor : "Apple", model : "Macintosh", type : undefined }
console.log(device2); // { vendor : "Apple", model : "iPad", type : "tablet" }
- https://docs.uaparser.js.org/v2/api/ua-parser-js/idata/with-feature-check.html
@faisalman Thanks for the workaround. Small question: Does calling .withFeatureCheck() also correct browser.name? Namely, update it from Safari to Mobile Safari?
Hi @faisalman what are valid values for model when using uap.getDevice().withFeatureCheck() ? will it detect iPhone ?
Since Apple froze its user agent in version 10.15.7, we haven't yet find a reliable solution that can be derived from only the user agent data (as in the Chrome Dev Tools case). However, if we are using a real browser in iPad we can try to do an additional check for iPad-specific browser features:由于Apple在10.15.7版本中冻结了其用户代理,我们还没有找到一个可靠的解决方案,可以只从用户代理数据(如Chrome Dev Tools案例)中导出。但是,如果我们在iPad中使用真实的浏览器,我们可以尝试对iPad特定的浏览器功能进行额外检查:
const uap = new UAParser(); const device1 = uap.getDevice(); const device2 = uap.getDevice().withFeatureCheck(); console.log(device1); // { vendor : "Apple", model : "Macintosh", type : undefined } console.log(device2); // { vendor : "Apple", model : "iPad", type : "tablet" }
- https://docs.uaparser.js.org/v2/api/ua-parser-js/idata/with-feature-check.html
https://docs.uaparser.dev/api/ua-parser-js/idata/with-feature-check.html