From c3a41b8cf3646ddd8791ab426ffb204ca5626da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 10 Feb 2021 10:24:04 +0100 Subject: [PATCH] fix(avatar) refactor preloading to avoid CORS issues Fixes: https://github.com/jitsi/jitsi-meet/issues/8510 This basically reverts https://github.com/jitsi/jitsi-meet/commit/a3fb996ff020a0984b0851981800a5e106e8a671 while retaining the same properties that prompted it's original intent, namely avoiding sending the Referrer header. --- .../base/participants/preloadImage.web.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/react/features/base/participants/preloadImage.web.js b/react/features/base/participants/preloadImage.web.js index 6e868cefc..2316fee8c 100644 --- a/react/features/base/participants/preloadImage.web.js +++ b/react/features/base/participants/preloadImage.web.js @@ -15,16 +15,13 @@ export function preloadImage(src: string | Object): Promise { } return new Promise((resolve, reject) => { - fetch(src, { referrer: '' }) - .then(response => { - if (response.ok) { - resolve(src); - } else { - reject(); - } - }) - .catch(e => { - reject(e); - }); + const image = document.createElement('img'); + + image.onload = () => resolve(src); + image.onerror = reject; + + // $FlowExpectedError + image.referrerPolicy = 'no-referrer'; + image.src = src; }); }