From 8d012a96f7f5eb1604ac99e241ba165d9f5bd369 Mon Sep 17 00:00:00 2001 From: sgenoud Date: Sun, 31 Mar 2019 19:56:21 +0200 Subject: [PATCH] fix: Enable PWA support for iOS devices (#1120) * Enable PWA support for iOS devices * add sniff for ios <12.2 --- src/inline-script/inline-script.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/inline-script/inline-script.js b/src/inline-script/inline-script.js index e5c6449..6064dce 100644 --- a/src/inline-script/inline-script.js +++ b/src/inline-script/inline-script.js @@ -51,8 +51,12 @@ if (/mac/i.test(navigator.platform)) { document.documentElement.style.setProperty('--scrollbar-border-radius', '50px') } -// TODO: remove this hack when Safari works with cross-origin window.open() -// in a PWA: https://github.com/nolanlawson/pinafore/issues/45 -if (/iP(?:hone|ad|od)/.test(navigator.userAgent)) { +// Versions of iOS Safari before iOS 12.2 do not work properly as a PWA +// for cross-origin authentication: https://github.com/nolanlawson/pinafore/issues/45 +// Here we sniff for iOS <12.2 by checking for the existence of a native IntersectionObserver +// function, which was added in 12.2. +if (/iP(?:hone|ad|od)/.test(navigator.userAgent) && + !(typeof IntersectionObserver === 'function' && + IntersectionObserver.toString().includes('[native code]'))) { document.head.removeChild(document.getElementById('theManifest')) }