Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/editor/src/extensions/embed/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Icons } from "../../toolbar/index.js";
import { Icon } from "@notesnook/ui";
import { Resizer } from "../../components/resizer/index.js";
import { useThemeEngineStore } from "@notesnook/theme";
import { useToolbarStore } from "../../toolbar/stores/toolbar-store.js";

export function EmbedComponent(
props: ReactNodeViewProps<EmbedAttributes & EmbedAlignmentOptions>
Expand All @@ -35,6 +36,7 @@ export function EmbedComponent(
const [isLoading, setIsLoading] = useState(true);
const { src, width, height, textDirection } = node.attrs;
const theme = useThemeEngineStore((store) => store.theme);
const corsHost = useToolbarStore((store) => store.downloadOptions?.corsHost);

let align = node.attrs.align;
if (!align) align = textDirection ? "right" : "left";
Expand Down Expand Up @@ -127,7 +129,10 @@ export function EmbedComponent(
? {
srcDoc: tweetToEmbed(src, theme.colorScheme === "dark")
}
: { src })}
: {
src:
isYouTubeEmbed(src) && corsHost ? `${corsHost}/${src}` : src
})}
width={"100%"}
height={"100%"}
sandbox={getSandboxFeatures(src)}
Expand Down Expand Up @@ -173,6 +178,18 @@ function getSandboxFeatures(src: string) {
return features.join(" ");
}

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/")
);
}

function isTwitterX(src: string) {
try {
const url = new URL(src);
Expand Down
Loading