2.2.1 • Published 22 days ago

@getmash/post-message v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
22 days ago

Post Message

Post Message library is a wrapper over the native browser PostMessage API. It creates a bi-directional tunnel between two instances of the library. Any messages not intended for the target will be ignored, reducing the noise that can be caused through PostMessage in the browser. It also supports restricting the origin which can receive messages sent from an instance of this library.

Installation

Install the package with:

yarn add @getmash/post-message
# or
npm install @getmash/post-message --save

Usage

import PostMessageEngine from "@getmash/post-message";

// in iframe

const receiver = new PostMessageEngine({
  name: "receiver",
  targetName: "sender",
  targetOrigin: "mysite.com",
  targetWindow: window.parent,
});

receiver.listen(msg => console.log(msg));

// in host page

const sender = new PostMessageEngine({
  name: "sender",
  targetName: "receiver",
  targetOrigin: "myiframe.com",
  targetWindow: iframe.window,
});

sender.send({ hello: "world" });
  • debug logs can be enabled with the environment variable DEBUG=mash:post-message
2.2.1

22 days ago

2.2.0

9 months ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

2 years ago

2.0.0-alpha.0

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago