Mantle App Bridge

The Mantle app bridge provides the following postMessage API to interact with the host Mantle application:


MessageDescription
mantle:bridge:setPagePrimaryActionSets the primary action button on the page.
mantle:bridge:setPageSets various page elements like primary action, back action, title, subtitle, title metadata, width, and secondary actions.
mantle:bridge:redirectRedirects the page to a new URL.
mantle:bridge:fullPageToggles the iframe to full page mode.
mantle:bridge:toastDisplays a toast message with a status (error or success).
mantle:bridge:setPathUpdates the browser's URL path.
mantle:bridge:sessionRequestRequests the current session data and sends it back to the iframe.
mantle:bridge:userRequestRequests the current user data and sends it back to the iframe.
mantle:bridge:showSaveBarShows the save bar on the page.
mantle:bridge:hideSaveBarHides the save bar on the page.
mantle:bridge:setSaveBarOptionsSets options for the save bar.
mantle:bridge:showAssetLibraryShows the asset library modal.
mantle:bridge:hideAssetLibraryHides the asset library modal.
mantle:bridge:hideModalBackgroundOverlayHides the modal background overlay.
mantle:bridge:showModalBackgroundOverlayShows the modal background overlay.
mantle:bridge:closeModalSent to the extension window in cases where the modal should be closed.

React.js example

export const fetchSessionFromMantle = async () => {
  return new Promise((resolve, reject) => {
    window.parent.postMessage(
      {
        type: "mantle:bridge:sessionRequest",
      },
      targetOrigin
    );

    const receiveSessionMessage = (event) => {
      if (event.origin !== targetOrigin) {
        reject(new Error("Invalid origin"));
        return;
      }

      try {
        if (event.data?.type === "mantle:bridge:sessionResponse") {
          if (event.data?.error) {
            reject(new Error("Failed to load session"));
          } else {
            resolve(event.data);
          }
          window.removeEventListener("message", receiveSessionMessage);
        }
      } catch (e) {
        console.error("Invalid data received:", event.data);
        reject(new Error("Failed to load session"));
      }
    };

    window.addEventListener("message", receiveSessionMessage);
  });
};