Socket
Socket
Sign inDemoInstall

cross-origin-courier

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cross-origin-courier

TODO


Version published
Weekly downloads
5
increased by25%
Maintainers
1
Install size
13.8 kB
Created
Weekly downloads
 

Readme

Source

npm npm bundle size NPM GitHub top language

This project is under active development.
Until major version released, the API is a subject to change.

cross-origin-courier

A wrapper over Window.postMessage() and MessageChannel to facilitate messaging between cross origin contexts.

The library exposes a connection function that returns a Promise. On a successful connection, the Promise is resolved with the courier object to be used to send and listen to messages. Note: the child frame should call the connection function first.

Setup

NPM
npm i cross-origin-courier
import connect from 'cross-origin-courier';
// ...
connect().then(courier => {
    courier.listen(handler);
    courier.send({ answer: 42 });
});

function handler(data) {
    // do your stuff
}
CDN
<script src="https://unpkg.com/cross-origin-courier"></script>

Loaded this way, the connection function is exposed under the following long-ish name

window.createCrossOrigConnection().then(courier => {
    // ...
});

Options

const options = {
    passphrase: 'foo-bar-baz-qux',
    isParent: true,
    targetOrigin: '*',
};
createConnection(options).then(courier => {
    // ...
});
OptionTypeDefaultDescription
passphrasestring'DEFAULT_PASSPHRASE'todo
targetOriginstring'*'todo
isParentbooleanfalsetodo

Courier API

MethodArgumentsDescription
senddata<any>Sends data to the counterparty
listendataHandler<(data: any) => void>Sets a handler for the counterparty messages

Documentation

Please find the full docs here

License

Copyright © 2021, Sergey Chernykh. Released under the MIT License.

Keywords

FAQs

Last updated on 05 Mar 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc