cross-origin-client
Version:
A client library for secure cross-origin communication using the postMessage API.
39 lines (24 loc) • 1.1 kB
Markdown
[](https://opensource.org/licenses/MIT)
Cross-Origin Client is a client library for secure cross-origin communication using the postMessage API. It simplifies cross-origin communication by providing a straightforward one-liner experience.
Install the library via npm:
```bash
npm install cross-origin-client
```
To use Cross-Origin Client in your project, import it and create an instance with trusted origin:
```javascript
import { CrossOriginClient } from "cross-origin-client";
// Create an instance of Cross-Origin Client
const client = new CrossOriginClient({ trustedOrigin: "https://example.com" });
```
You can send messages to trusted origin using the `send` method:
```javascript
const messageType = "messageTypeSupportedByTheReceivingSide";
const response = await client.send({ type: messageType });
console.log("Response received:", response);
```
This project is licensed under the MIT License.