From 26a5bb0dcbd110bbbd0d9f93598a0e7f498cd4d2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 29 May 2019 13:05:59 +0200 Subject: [PATCH 1/2] exclude chrome in ua from safari version check for colr support --- src/utils/FontManager.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/FontManager.js b/src/utils/FontManager.js index c7a1f5e0b6..b9e33c2c4e 100644 --- a/src/utils/FontManager.js +++ b/src/utils/FontManager.js @@ -22,6 +22,7 @@ limitations under the License. */ function safariVersionCheck(ua) { + console.log("Browser is Safari - checking version for COLR support"); try { const safariVersionMatch = ua.match(/Mac OS X ([\d|_]+).*Version\/([\d|.]+).*Safari/); if (safariVersionMatch) { @@ -31,7 +32,7 @@ function safariVersionCheck(ua) { const safariVersion = safariVersionStr.split(".").map(n => parseInt(n, 10)); const colrFontSupported = macOSVersion[0] >= 10 && macOSVersion[1] >= 14 && safariVersion[0] >= 12; // https://www.colorfonts.wtf/ states safari supports COLR fonts from this version on - console.log(`Browser is Safari - requiring macOS 10.14 and Safari 12, ` + + console.log(`COLR support on Safari requires macOS 10.14 and Safari 12, ` + `detected Safari ${safariVersionStr} on macOS ${macOSVersionStr}, ` + `COLR supported: ${colrFontSupported}`); return colrFontSupported; @@ -45,19 +46,21 @@ function safariVersionCheck(ua) { async function isColrFontSupported() { console.log("Checking for COLR support"); + const {userAgent} = navigator; // Firefox has supported COLR fonts since version 26 // but doesn't support the check below without // "Extract canvas data" permissions // when content blocking is enabled. - if (navigator.userAgent.includes("Firefox")) { + if (userAgent.includes("Firefox")) { console.log("Browser is Firefox - assuming COLR is supported"); return true; } // Safari doesn't wait for the font to load (if it doesn't have it in cache) // to emit the load event on the image, so there is no way to not make the check // reliable. Instead sniff the version. - if (navigator.userAgent.includes("Safari")) { - return safariVersionCheck(navigator.userAgent); + // Excluding "Chrome", as it's user agent unhelpfully also contains Safari... + if (!userAgent.includes("Chrome") && userAgent.includes("Safari")) { + return safariVersionCheck(userAgent); } try { From 379336124053973df29061f94e9749da79147acc Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 29 May 2019 13:24:46 +0200 Subject: [PATCH 2/2] always log on return false --- src/utils/FontManager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/FontManager.js b/src/utils/FontManager.js index b9e33c2c4e..796018a497 100644 --- a/src/utils/FontManager.js +++ b/src/utils/FontManager.js @@ -38,8 +38,9 @@ function safariVersionCheck(ua) { return colrFontSupported; } } catch (err) { - console.error("Couldn't determine Safari version to check COLR font support, assuming no.", err); + console.error("Error in Safari COLR version check", err); } + console.warn("Couldn't determine Safari version to check COLR font support, assuming no."); return false; }