FIX: Better detection of Apple browsers (#7961)

Introduces isIpadOS to our capabilities sniffer, which is currently
compatible with latest iPad beta OS. Older iPad versions will match our
isIOS detection.

Using this new feature, fixes the service worker being blocked in Google
Chrome, Firefox and other browsers while running on Mac OS, where they
work just fine. This enables Desktop PWA install in Mac OS.
This commit is contained in:
Rafael dos Santos Silva 2019-08-02 12:43:25 -03:00 committed by GitHub
parent 06e757245f
commit 272b38a573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -9,7 +9,8 @@ export default {
const isSupported = isSecured && "serviceWorker" in navigator;
if (isSupported) {
const isApple = !!navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i);
const caps = Discourse.__container__.lookup("capabilities:main");
const isApple = caps.isSafari || caps.isIOS || caps.isIpadOS;
if (Discourse.ServiceWorkerURL && !isApple) {
navigator.serviceWorker.getRegistrations().then(registrations => {

View File

@ -37,6 +37,8 @@ export default {
caps.isIOS =
/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
caps.isIpadOS = ua.indexOf("Mac OS") !== -1 && touch;
}
// We consider high res a device with 1280 horizontal pixels. High DPI tablets like