Embed

# Fetching from URL

By adding ?json=https://catfact.ninja/fact query at the end of iframe src you will be able to fetch from URL at widgets without additional scripts. This applies to editor page as well, the following link will fetch the url at the editor: https://jsoncrack.com/editor?json=https://catfact.ninja/fact

# Communicating with API

◼︎ Post Message to Embed

Communicating with the embed is possible with MessagePort, you should pass an object consist of "json" and "options" key where json is a string and options is an object that may contain the following:

{
  theme: "light" | "dark",
  direction: "TOP" | "RIGHT" | "DOWN" | "LEFT"
}

◼︎ On Page Load

⚠️ Important! - iframe should be defined before the script tag

⚠️ Note - Widget is not loaded immediately with the parent page. The widget sends its id attribute so you can listen for it as in the example below to ensure its loaded and ready to listen for messages.