fix(avatar) refactor preloading to avoid CORS issues

Fixes: https://github.com/jitsi/jitsi-meet/issues/8510

This basically reverts
a3fb996ff0
while retaining the same properties that prompted it's original intent, namely
avoiding sending the Referrer header.
This commit is contained in:
Saúl Ibarra Corretgé 2021-02-10 10:24:04 +01:00 committed by Saúl Ibarra Corretgé
parent f4d0ec1bb4
commit c3a41b8cf3
1 changed files with 8 additions and 11 deletions

View File

@ -15,16 +15,13 @@ export function preloadImage(src: string | Object): Promise<string> {
}
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;
});
}