
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
message-channel-promise
Advanced tools
Promise wrapper for communication via post message and MesssageChannel
Promise wrapper for communication via post message and MesssageChannel
npm i message-channel-promise
The module exposes a function which can be used to wrap communication via MessageChannel in a promise, resolved only when the recepient responds.
This works with IFrames and web workers, and message ports.
message
: The message to send. Must be a serializable JSON object.target
: The contentWindow
or worker. can be omitted if sending from worker, since it sends messages to itself.options
: contains optional parameters (optional):
targetOrigin
(optional): The origin to send the message to. Defaults to *
, and not necessary for web workers or message ports.transfer
(optional): a list of other Transferrable objects to be passed.You should always send a targetOrigin when working with iFrames.
Usage with IFrames:
const sendChannelMessage = require('message-channel-promise');
const frame = document.querySelector('#iframe');
const message = {/* ... */};
sendChannelMessage(message, frame.contentWindow, {targetOrigin: '*'})
.then(function(data) {
// Do something with the response
});
Usage with Web Workers:
const sendChannelMessage = require('message-channel-promise');
const worker = new Worker(someScript);
sendChannelMessage(message, worker)
.then(function (data) {
// Do something with the response
});
Usage with MessagePort objects:
const sendChannelMessage = require('message-channel-promise');
//get port from somewhere, can also be from other context
sendChannelMessage(message, port)
.then(function (data) {
// Do something with the response
})
FAQs
Promise wrapper for communication via post message and MesssageChannel
The npm package message-channel-promise receives a total of 5 weekly downloads. As such, message-channel-promise popularity was classified as not popular.
We found that message-channel-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.