New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ameerthehacker/frame-rpc

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ameerthehacker/frame-rpc

Communication between browser windows using jsonrpc

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Frame RPC

Iframe/Window communications using post messages is such a pain in the arse

  • Manage handshakes
  • We don't get strong contract
  • Write never ending switch statements

This reimagines Iframe communication using JSON RPC. What if you can just call a function to do something in your iframe without thinking in terms of postmessages and get something back without thinking about listening for messages?

Demo

Play with sandbox here

How to use it?

In the Iframe application

import { createBackend } from '@ameerthehacker/frame-rpc';

createBackend({
  add: (num1, num2) => {
    return num1 + num2;
  },
});

In the main application

import { FrameRPC } from '@ameerthehacker/frame-rpc';

const iframeElement = document.getElementById('iframe-element');
const iframeRPC = new FrameRPC(iframeElement.contentWindow);

await iframeRPC.handshake();

const frontend = iframeRPC.createFrontend();
const result = await frontend.add(2, 5);

// will print 7 😃
console.log(result);

You can have strong contracts using typescript generic and you can refer to the code in playground for samples.

Try locally

yarn
yarn start

License

MIT © Ameer Jhan

Keywords

FAQs

Package last updated on 23 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc