Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3038 from matrix-org/bwindels/colr-check-race2
Browse files Browse the repository at this point in the history
Exclude chrome in ua from safari version check for colr support
  • Loading branch information
bwindels authored May 29, 2019
2 parents f61e771 + 3793361 commit d34d5f1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/utils/FontManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -31,33 +32,36 @@ 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;
}
} 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;
}

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 {
Expand Down

0 comments on commit d34d5f1

Please sign in to comment.