A simple promise-based client and server to communicate between pages and iframes with postmessage.
All data passed will be serialized with JSON.
In your project dir:
npm install --save postmessage-client-server
In your page the iframe will load on your server:
On your client webpage:
;const urlToServerPage = '';// adds an iframe to the given url in your page;
The console output from the above example would be:
SERVER: Sniffing...CLIENT: We smelt: "grass" "ball"SERVER: Bark at grassSERVER: Bark at ballSERVER: About to misbehave...CLIENT: Got punished for Eating shoeCLIENT: Bark result: Barked at grassCLIENT: Bark result: Barked at ball
Remember that the calls are asynchronous, so the order may vary.