spark.createParentRpc
function createParentRpc(): RpcCreate an RPC instance for communicating with the parent window (iframe).
Used in sandboxed iframes to communicate with the parent/embedding page. Useful for passing data and control between iframe and parent.
Equivalent to: new Rpc({ target: window.parent, origin: '*' })
Origins are set to '*' for convenience. For cross-origin communication, create a custom Rpc instance with specific origin validation.
Returns
Rpc– RPC instance connected to parent windowExamples
// In a sandboxed iframe:
try {
const rpc = createParentRpc();
// Register handlers for parent messages
rpc.handle('receive.code', async (code) => {
// Hot reload new code
eval(code);
});
// Request data from parent
const data = await rpc.call('parent.getData');
// Send updates back to parent
rpc.notify('iframe.ready', { loaded: true });
} catch (err) {
console.error('Not in iframe:', err.message);
}See Also
- createWorkerRpc - Create RPC to worker
- createSelfRpc - Create RPC in worker context