From 04cac0c4078a683ddc78796a9e0a0482c4e6d1ba Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Mon, 31 Aug 2020 15:19:06 -0400 Subject: [PATCH] Fix iPad detection --- src/scripts/browser.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/scripts/browser.js b/src/scripts/browser.js index 618d930ec8..9f81ec7561 100644 --- a/src/scripts/browser.js +++ b/src/scripts/browser.js @@ -75,10 +75,24 @@ function hasKeyboard(browser) { function iOSversion() { // MacIntel: Apple iPad Pro 11 iOS 13.1 if (/iP(hone|od|ad)|MacIntel/.test(navigator.platform)) { - // supports iOS 2.0 and later: - const v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/); - return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; + const tests = [ + // Original test for getting full iOS version number in iOS 2.0+ + /OS (\d+)_(\d+)_?(\d+)?/, + // Test for iPads running iOS 13+ that can only get the major OS version + /Version\/(\d+)/ + ]; + for (const test of tests) { + const matches = (navigator.appVersion).match(test); + if (matches) { + return [ + parseInt(matches[1], 10), + parseInt(matches[2] || 0, 10), + parseInt(matches[3] || 0, 10) + ]; + } + } } + return []; } let _supportsCssAnimation; @@ -196,6 +210,15 @@ if (!browser.chrome && !browser.edgeChromium && !browser.edge && !browser.opera browser.safari = true; } +browser.osx = userAgent.toLowerCase().indexOf('os x') !== -1; + +// This is a workaround to detect iPads on iOS 13+ that report as desktop Safari +// This may break in the future if Apple releases a touchscreen Mac +// https://forums.developer.apple.com/thread/119186 +if (browser.osx && !browser.iphone && !browser.ipod && !browser.ipad && navigator.maxTouchPoints > 1) { + browser.ipad = true; +} + if (userAgent.toLowerCase().indexOf('playstation 4') !== -1) { browser.ps4 = true; browser.tv = true; @@ -242,7 +265,6 @@ if (typeof document !== 'undefined') { browser.keyboard = hasKeyboard(browser); browser.supportsCssAnimation = supportsCssAnimation; -browser.osx = userAgent.toLowerCase().indexOf('os x') !== -1; browser.iOS = browser.ipad || browser.iphone || browser.ipod; if (browser.iOS) {