From a3fb996ff020a0984b0851981800a5e106e8a671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 14 Oct 2020 21:58:28 +0200 Subject: [PATCH] fix(avatars) refactor preloading Use fetch(), which gives us better control over headers. --- .../base/participants/preloadImage.web.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/react/features/base/participants/preloadImage.web.js b/react/features/base/participants/preloadImage.web.js index 29fb2ae18..6e868cefc 100644 --- a/react/features/base/participants/preloadImage.web.js +++ b/react/features/base/participants/preloadImage.web.js @@ -15,10 +15,16 @@ export function preloadImage(src: string | Object): Promise { } return new Promise((resolve, reject) => { - const image = document.createElement('img'); - - image.onload = () => resolve(src); - image.onerror = reject; - image.src = src; + fetch(src, { referrer: '' }) + .then(response => { + if (response.ok) { + resolve(src); + } else { + reject(); + } + }) + .catch(e => { + reject(e); + }); }); }