Oceansdeep7 / code-snippet

0 stars 0 forks source link

Detect iOS without using user agent #1

Open Oceansdeep7 opened 4 months ago

Oceansdeep7 commented 4 months ago

To avoid reading the user agent string, check the standalone property of the navigator object. This is a non-standard property, and it's only available on the WebKit engine on iOS and iPadOS.

If navigator.standalone is undefined it means the user is not on an iPadOS or iOS device. If navigator.standalone is false it means the user opened the PWA in the browser and is using it there. If navigator.standalone is true it means the user opened the PWA from the home screen and is getting the standalone PWA experience.

Oceansdeep7 commented 2 months ago

const UA = navigator.userAgent; const isWebkit = /\b(iPad|iPhone|iPod)\b/.test(UA) && /WebKit/.test(UA) && !/Edge/.test(UA) && !window.MSStream;

Oceansdeep7 commented 2 months ago

https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent