Fix crash when media url doesn't have http prefix

This commit is contained in:
Lim Chee Aun 2024-05-17 17:10:54 +08:00
parent b0a53b7fa1
commit 62f843b4dc

View file

@ -166,7 +166,7 @@ function Media({
[to], [to],
); );
const remoteMediaURLObj = remoteMediaURL ? new URL(remoteMediaURL) : null; const remoteMediaURLObj = remoteMediaURL ? getURLObj(remoteMediaURL) : null;
const isVideoMaybe = const isVideoMaybe =
type === 'unknown' && type === 'unknown' &&
remoteMediaURLObj && remoteMediaURLObj &&
@ -618,4 +618,13 @@ function Media({
} }
} }
function getURLObj(url) {
try {
// Fake base URL if url doesn't have https:// prefix
return new URL(url, location.origin);
} catch (e) {
return null;
}
}
export default Media; export default Media;