Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. Spark
  3. spark
  4. createParentRpc

spark.createParentRpc

function createParentRpc(): Rpc

Create 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 window

Examples

// 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
Previous
clearLocal
Next
createSelfRpc