Communication-bridge
Overview
A cross-domain communication library develop by Rand Labs that enables send and receive messages between browser windows/tabs.
Instalation
The library can be installed via npm:
npm i @randlabs/communication-bridge
API Usage
Import and define the communication channel
const Messenger = require("@randlabs/communication-bridge");
const channelName = "channel name";
Tab #1
const client = new Messenger(channelName);
const window = window.open("https://another.website.com");
const response = await client.sendMessage(window, { customMethod: "doSomething" }, { waitForReply: true, origin: "*" });
console.log(response);
Tab #2
const hub = new Messenger(channelName, function(data, origin, source, sendResponse) {
console.log(data);
sendResponse({ response: "OK" });
});
Copyright and License
See LICENSE file.