editor: fix crash if embed url is invalid or empty

This commit is contained in:
Abdullah Atta
2026-02-21 10:30:18 +05:00
parent 7da168ab52
commit 656f87e3c6

View File

@@ -179,15 +179,19 @@ function getSandboxFeatures(src: string) {
}
function isYouTubeEmbed(urlString: string) {
const url = new URL(urlString);
return (
(url.hostname === "www.youtube.com" ||
url.hostname === "youtube.com" ||
url.hostname === "m.youtube.com" ||
url.hostname === "www.youtube-nocookie.com" ||
url.hostname === "youtube-nocookie.com") &&
url.pathname.startsWith("/embed/")
);
try {
const url = new URL(urlString);
return (
(url.hostname === "www.youtube.com" ||
url.hostname === "youtube.com" ||
url.hostname === "m.youtube.com" ||
url.hostname === "www.youtube-nocookie.com" ||
url.hostname === "youtube-nocookie.com") &&
url.pathname.startsWith("/embed/")
);
} catch {
return false;
}
}
function isTwitterX(src: string) {