From ff75364f22453cdf212b00a4dbd533b108eb5857 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Wed, 7 Jun 2023 14:13:12 +0530 Subject: [PATCH] Fix embed detection (#9385) --- packages/embeds/embed-core/embed-iframe-init.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/embeds/embed-core/embed-iframe-init.ts b/packages/embeds/embed-core/embed-iframe-init.ts index 3b73d4fdfe..a48999b147 100644 --- a/packages/embeds/embed-core/embed-iframe-init.ts +++ b/packages/embeds/embed-core/embed-iframe-init.ts @@ -11,10 +11,13 @@ export default function EmbedInitIframe() { // So, we also check for the namespace in `window.name` which is set when iframe is created by embed.ts and persists for the duration of iframe's life // Note that, window.name isn't lost during hard navigation as well. Though, hard navigation isn't something that would happen in the app, but it's critical to be able to detect embed mode even after that(just in case) // We might just use window.name but if just in case something resets the `window.name`, we will still have the namespace in query param + // It must be null for non-embed scenario. const embedNamespace = typeof embedNameSpaceFromQueryParam === "string" ? embedNameSpaceFromQueryParam - : window.name.replace(/cal-embed=(.*)/, "$1").trim(); + : window.name.includes("cal-embed=") + ? window.name.replace(/cal-embed=(.*)/, "$1").trim() + : null; window.isEmbed = () => { // By default namespace is "". That would also work if we just check the type of variable