Files
jitsi-meet/react/features/base/participants/preloadImage.web.js
Saúl Ibarra Corretgé c3a41b8cf3 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.
2021-02-10 14:32:56 +01:00

28 lines
599 B
JavaScript

// @flow
import { isIconUrl } from './functions';
/**
* Tries to preload an image.
*
* @param {string | Object} src - Source of the avatar.
* @returns {Promise}
*/
export function preloadImage(src: string | Object): Promise<string> {
if (isIconUrl(src)) {
return Promise.resolve(src);
}
return new Promise((resolve, reject) => {
const image = document.createElement('img');
image.onload = () => resolve(src);
image.onerror = reject;
// $FlowExpectedError
image.referrerPolicy = 'no-referrer';
image.src = src;
});
}