Talking to the page: ZuperEmbed
The page inside a Frame and your app can send each other messages. The page uses @zuperpro/app-sdk/embed.
| Your page is | Load ZuperEmbed with |
|---|---|
| A bundled page (Vite, webpack …) | import { ZuperEmbed } from '@zuperpro/app-sdk/embed' |
| A plain HTML page | Copy node_modules/@zuperpro/app-sdk/dist/zuper-embed.js next to it and load it with <script src="zuper-embed.js"></script>. It defines the global ZuperEmbed. |
On the page
ZuperEmbed.ready.then(({ appId }) => {
// Zuper connected.
});
ZuperEmbed.on('job', (content) => showJob(content));
ZuperEmbed.send('picked', { item: 'Air filter 20x25', qty: 2 });In the dialog
import { useRef, useState } from 'react';
import { Button, Frame, type FrameHandle, type FrameMessage } from '@zuperpro/app-sdk/react';
const frame = useRef<FrameHandle>(null);
const [last, setLast] = useState<FrameMessage | null>(null);
<Frame ref={frame} src="https://pages.acme.com/picker" height="fill" onMessage={setLast} />
<Button label="Send job" onPress={() => frame.current?.send('job', { title: record.title })} />Rules
readyresolves when Zuper connects. It never resolves outside a ZuperFrame.sendwaits for it.- Message size:
typeis 1–100 characters.contentmust be JSON data up to 64 KB. - Only between the page and its app. The page accepts messages only from its parent on a Zuper origin, and sends only to the origin that connected. Zuper passes messages only from the frame it drew, from that page's origin.
- Never Zuper's APIs. Your app decides what each message does, with the user's permissions.
Not v1.
@zuperpro/app-sdk/embedis separate from ZDK v1'szsdk-embed.js. Don't mix them.
Updated about 1 hour ago
Did this page help you?
