Initialize Canvas
Embed the Canvas iframe and dispatch the first view payload.
Set the Canvas URL, mount the iframe, and send a view message after the canvas is ready to receive host messages.
- Keep the canvas origin and URL in a single configuration module.
- Attach the iframe
loadhandler before assigningiframe.src. - Wait briefly after iframe load before posting the first message.
- Send a
viewpayload with a file URL to bootstrap the session.
Define the Canvas URL once and reuse it across canvas sessions.
Create the iframe without src in the markup. Register the load handler first, then assign iframe.src. This prevents a fast iframe load from firing before your handler exists.
Do not put src directly on the iframe if your integration depends on catching the first load event. The browser can load a cached iframe before your script registers the handler.
Also avoid sending view immediately at iframe load time. The iframe document may be loaded while the canvas app is still registering its message listener.
Reuse a typed payload shape to keep canvas messages consistent.
Use progressStart and progressEnd to drive loading UI while the canvas prepares files. progressStart also confirms that the first view message was received.
A full example with configuration, iframe lifecycle, and the initial view message.
