UNPKG

cross-origin-client

Version:

A client library for secure cross-origin communication using the postMessage API.

39 lines (24 loc) 1.1 kB
# Cross-Origin Client [![License](https://img.shields.io/badge/license-MIT-blue.svg)](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. ## Installation Install the library via npm: ```bash npm install cross-origin-client ``` ## Usage 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" }); ``` ### Sending Messages 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); ``` ## License This project is licensed under the MIT License.