marknotton / craft-plugin-agent

Query the server-side information from the users agent data.
MIT License
7 stars 4 forks source link

Ipad pro does not count as a tablet #16

Open danfathom opened 1 year ago

danfathom commented 1 year ago

Ipad pro does not count as a tablet for some reason.

I've been testing on a ipad pro 12.9 2020.

Any ideas how I can get it to show ipad pros as a tablet? Or is there a way to target all touch devices?

danfathom commented 1 year ago

It also comes back at true, when doing window.isDesktop on a ipad pro

marknotton commented 1 year ago

This is a browser setting. The Chrome browser on iPad uses "Desktop" as the default site view. You can change this by going to "Settings > Content Settings > Default site view" in your Chrome App. Though I wouldn't recommend this as it's unlikely anyone will actually change this setting in the real world.

The Agent plugin is determining the device type as it is provided by the Chrome apps user agent string. So not much can be done I'm afraid. There may be other properties in the user agent string that could be queried to determine the iPad is not a desktop regardless of the "Default site view" setting... but I'm unaware of any at this time.

As for detecting touch devices, this can't be done using server side scripts that I know of. It's client specific and can only be done reliably with Javascript:

window.hasTouch = (() => ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch || false )()
console.log(hasTouch)