Closed st-h closed 1 year ago
Possible workaround is to check for touch device.
If it shows as macOS and it's touch enabled, then it is an iPad
const isTouchEnabled = "ontouchend" in document; // true for iPad, false for MacBook
@bartoszhernas thanks for the suggestion. Unfortunately this is used in a node environment and the only way to identify the device is via user agent. Already checking for ontouchend when run inside the browser, but that unfortunately does not work within node. I am not even sure if this can be fixed, as the user agent seems to be very similar to the MacOS user agent.
You are right, it will only work on client side. Backend side it will not be possible anymore I believe, based purely on user agent you've sent, there is nothing to distinguish if it's an iPad.
As an iPad user, I like this, as sometimes websites would show me badly made mobile versions of websites. As a developer, it's crazy if there truly is not other way to distinguish.
Unfortunately there is still no workaround when working in node environment since it heavily relies on user-agent information.
Only after being loaded in browser it can be re-checked using withFeatureCheck()
method.
// suppose this code runs on iPad
const withoutFeatureCheck = UAParser();
const withFeatureCheck = UAParser().withFeatureCheck();
console.log(withoutFeatureCheck.device); // { vendor : "Apple", model : "Macintosh", type : undefined }
console.log(withFeatureCheck.device); // { vendor : "Apple", model : "iPad", type : "tablet" }
https://docs.uaparser.js.org/v2/api/ua-parser-js/idata/with-feature-check.html
Newer iPad OS versions (in this case iPadOS 16.1.1) seem to be recognised as MacOS. Here is the full result: