From a00003004045eca86b26214cf6847188f5146b63 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Mon, 20 Feb 2023 17:01:56 +0530 Subject: [PATCH] Check embed in a better way (#7221) --- apps/web/pages/_document.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/web/pages/_document.tsx b/apps/web/pages/_document.tsx index cd0201dc54..2d92e21ddb 100644 --- a/apps/web/pages/_document.tsx +++ b/apps/web/pages/_document.tsx @@ -18,7 +18,10 @@ class MyDocument extends Document { // If x-csp not set by gSSP, then it's initialPropsOnly ctx.res?.setHeader("x-csp", "initialPropsOnly"); } - const isEmbed = ctx.asPath?.includes("/embed") || ctx.asPath?.includes("embedType="); + const asPath = ctx.asPath || ""; + // Use a dummy URL as default so that URL parsing works for relative URLs as well. We care about searchParams and pathname only + const parsedUrl = new URL(asPath, "https://dummyurl"); + const isEmbed = parsedUrl.pathname.endsWith("/embed") || parsedUrl.searchParams.get("embedType") !== null; const initialProps = await Document.getInitialProps(ctx); return { isEmbed, nonce, ...initialProps }; }