fix: Add navigatedToBooker event and fix infinite loop of events (#14694)

## What does this PR do?

1. cal.com/sales page is a special case where embed-iframe exists in top as well as in iframe. This causes a looping of events somehow due to embed-iframe firing events and those being received by the top embed-iframe.
2. Added new `navigatedToBooker` event to know when the user lands on booker page.


Corresponding PR in website that uses `navigatedToBooker` event  and has a demo as well https://github.com/calcom/website/pull/741

Earlier added `routed` event seems to happen too early

## Type of change
- Bug fix (non-breaking change which fixes an issue)

## How should this be tested?
- Simply navigate to booker and wait for the event.

## Mandatory Tasks
- [x] Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

## Tests
- Didn't add any tests for this as the changed seems straightforward

## Checklist
- I haven't added tests that prove my fix is effective or that my feature works
This commit is contained in:
Hariom Balhara authored and GitHub committed 2024-04-23 10:36:12 +01:00
1 parent 9215725dad
commit ed76d163cf
3 files changed
+16 -2

No files matched your search

@@ -508,7 +508,10 @@ function keepParentInformedAboutDimensionChanges() {
});
}
if (isBrowser) {
function main() {
if (!isBrowser) {
return;
}
log("Embed SDK loaded", { isEmbed: window?.isEmbed?.() || false });
const url = new URL(document.URL);
embedStore.theme = window?.getEmbedTheme?.();
@@ -523,6 +526,9 @@ if (isBrowser) {
// If embed link is opened in top, and not in iframe. Let the page be visible.
if (top === window) {
unhideBody();
// We would want to avoid a situation where Cal.com embeds cal.com and then embed-iframe is in the top as well. In such case, we would want to avoid infinite loop of events being passed.
log("Embed SDK Skipped as we are in top");
return;
}
window.addEventListener("message", (e) => {
@@ -618,3 +624,5 @@ function connectPreloadedEmbed({ url }: { url: URL }) {
const isPrerendering = () => {
return new URL(document.URL).searchParams.get("prerender") === "true";
};
main();
@@ -60,6 +60,7 @@ export type EventDataMap = {
actionType: "customPageMessage" | "externalRedirectUrl" | "eventTypeRedirectUrl";
actionValue: string;
};
navigatedToBooker: Record<string, never>;
"*": Record<string, unknown>;
__routeChanged: Record<string, never>;
__windowLoadComplete: Record<string, never>;