0

I'm trying to detect if a user visiting my webapp is a mobile user or not. I've seen various implementations (example1, example2, example3) but none of them seem to be foolproof or recommended.

I have never seen anyone mention checking if (navigator.share) as a method to determine if a user is on mobile or desktop. The if statement correctly distinguishes between desktop and mobile users in my app (source).

Can I rely on this if statement check? If not, what are the drawbacks to using this approach?

(Note: caniuse states that navigator.share only has 87% coverage, but what if I just assume that's "good enough"?)

AlbertL
  • 11
  • 4
  • From the linked caniuse, it looks like this is supported by Chrome and Edge on Windows and ChromeOS. Since those aren't mobile users, I'd say this isn't the best option. – lukew3 May 31 '22 at 05:07

1 Answers1

0

Microsoft Edge on Windows supports the Web Share API, so this is definitely not a good method to distinguish mobile from desktop users. On modern Chromium browsers, you can simply call the following API:

const isMobile = navigator.userAgentData.mobile;
DenverCoder9
  • 2,024
  • 11
  • 32