@seibert/frame-bridge
v1.0.4
Published
A lightweight JavaScript library for seamless communication between a website and embedded iframes. frame-bridge simplifies the integration process by providing a secure and efficient way to exchange messages using the PostMessage API.
Downloads
21
Readme
Frame Bridge
Usage top level frame
Start host listener
startHostListener: (navigation: NavigationFn) => void
Initialize host listener with navigation function. The navigation function is called when a navigation event is triggered. It must be of type NavigationFn.
export type NavigateFn = ({ contentId, spaceKey }: { contentId: string; spaceKey?: string }) => Promise<boolean>;
import { startHostListener } from "@seibert/frame-bridge";
startHostListener(onNavigate)
Usage embedded frame
Validate if top level frame started host listener
isHostListening: () => Promise<boolean>
Call function isHostListening, which returns true if host is listening
import { isHostListening } from "@seibert/frame-bridge";
(async () => {
const isListening = await isHostListening();
console.log("Is host listening?", isListening);
})()
Check if top level frame handled navigation
onNavigationToConfluenceContent: ({ contentId, spaceKey }: { contentId: string; spaceKey?: string }) => Promise<{ isResponsible: boolean }>
Call function onNavigationToConfluenceContent with contentId and spaceKey of the space to navigate to. It returns { isResponsible: true } if top level frame handled navigation.
import { onNavigationToConfluenceContent } from "@seibert/frame-bridge";
onNavigationToConfluenceContent({
contentId: "1933581",
spaceKey: "Duck",
}).then((res) => console.log("RESULT NAV: ", res.isResponsible));