From 6435985fe60b08b248165872f76227f3290530fa Mon Sep 17 00:00:00 2001 From: eight Date: Mon, 19 Nov 2018 16:49:45 +0800 Subject: [PATCH] Fix: fetch text in Chrome 49 --- content/install-hook-usercss.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/content/install-hook-usercss.js b/content/install-hook-usercss.js index 622b3143..c88c13ea 100644 --- a/content/install-hook-usercss.js +++ b/content/install-hook-usercss.js @@ -54,6 +54,12 @@ } function fetchText(url) { + // XHR throws in Chrome 49 + // FIXME: choose a correct version + // https://github.com/openstyles/stylus/issues/560 + if (getChromeVersion() <= 49) { + return fetch(url).then(r => r.text()); + } return new Promise((resolve, reject) => { // you can't use fetch in Chrome under 'file:' protocol const xhr = new XMLHttpRequest(); @@ -64,6 +70,11 @@ }); } + function getChromeVersion() { + const match = navigator.userAgent.match(/chrome\/(\d+)/i); + return match && Number(match[1]); + } + function start() { timer = timer || setTimeout(check, DELAY); }