mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-05-18 05:05:36 +02:00
editor: fix youtube embeds erroring with code 153 (#9180)
* web: add referer header with content origin * youtube embeds aren't working without adding this header Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> * editor: use corsHost for youtube embeds * editor: make youtube embed detection more robust * web: remove referrer meta tag --------- Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> Co-authored-by: Ammar Ahmed <ammarahmed6506@gmail.com> Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
This commit is contained in:
@@ -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>
|
||||
@@ -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";
|
||||
@@ -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)}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user