🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

xwm

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xwm

Simple cross-window messaging library

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

XWM

Cross-window messaging library.

Usage

npm install xwm

Main Window

import { create } from "/lib/main.ts";

// Define the events
interface EventMap {
    ping: { timestamp: number };
    pong: { timestamp: number };
}

const url = "http://example.com";

// Create instance
const xwm = create<EventMap>(url);

// Open window in an iframe and pass the token
const iframe = document.createElement("iframe");
iframe.src = `${url}?token=${xwm.createToken()}`;
document.body.appendChild(iframe);

// Register the created window
xwm.setPeerWindow(iframe.contentWindow);

// Listen for events
xwm.on("pong", (payload) => {
    console.log("Pong received", payload.timestamp);
});

// Emit events
xwm.emit("ping", { timestamp: Date.now() });

Peer Window

import { createFromToken } from "/lib/main.ts";

// Get the token
const params = new URLSearchParams(location.search).get("token");

// Create instance from token
const xwm = createFromToken<EventMap>(token);

// Listen for events
xwm.on("ping", (payload) => {
    console.log("Ping received", payload.timestamp);

    // Emit events
    xwm.emit("pong", { timestamp: Date.now() });
});

Keywords

cross-window

FAQs

Package last updated on 24 Jan 2023

Did you know?

Socket

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