editor: fix youtube embeds

This commit is contained in:
Abdullah Atta
2025-02-17 10:28:06 +05:00
committed by Abdullah Atta
parent f772cf0f14
commit 49ffcbea03

View File

@@ -115,10 +115,10 @@ export function EmbedComponent(
</Box>
<Embed
ref={embedRef}
src={src.startsWith("javascript:") ? "about:blank" : src}
src={src}
width={"100%"}
height={"100%"}
sandbox="allow-scripts"
sandbox={getSandboxFeatures(src)}
sx={{
bg: "var(--background-secondary)",
border: selected
@@ -147,3 +147,15 @@ export function EmbedComponent(
</Flex>
);
}
function getSandboxFeatures(src: string) {
const features = [];
try {
const url = new URL(src);
if (url.protocol === "http:" || url.protocol === "https:")
features.push("allow-scripts", "allow-same-origin");
} catch {
// ignore
}
return features.join(" ");
}