npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

iframe-connect

v1.1.2

Published

A lightweight, type-safe cross-frame communication library with plugin system and multi-window isolation

Readme

iframe-connect

A lightweight, type-safe cross-frame communication library.

Features

  • 🚀 Lightweight - Simple core code, no external dependencies, only ~9KB in size
  • 🔒 Type-Safe - Full TypeScript support with generic-friendly interfaces
  • 🎯 Easy to Use - Intuitive API design
  • 🔌 Plugin System - Support for logging, retry, queue, and other extensions
  • 🔄 Bidirectional - Request/response pattern support
  • 🛡️ Multi-Window Isolation - Optional message isolation between windows

Installation

npm install iframe-connect

Basic Usage

Simple API

import { createBridge } from "iframe-connect";

// Auto-detect environment (parent window or child window)
const bridge = createBridge(iframe); // Provide iframe in parent window
// OR
const bridge = createBridge(); // No parameters needed in child window

// Send a message
bridge.send("greeting", { message: "Hello!" });

// Send a request and wait for response
const response = await bridge.request("getData", { id: 123 });
console.log(response);

// Listen for messages
bridge.on("notification", (payload) => {
  console.log("Received notification:", payload);
});

With Plugins

import { createBridge } from "iframe-connect";

const bridge = createBridge(iframe, {
  // Basic configuration
  targetOrigin: "https://trusted-domain.com",
  debug: true,

  // Plugin configuration
  plugins: {
    // Enable logger plugin
    logger: {
      level: "info",
      colors: true,
    },

    // Enable retry functionality
    retry: {
      maxRetries: 3,
    },

    // Enable queue management
    queue: {
      batchSize: 5,
    },
  },
});

// Use API normally (already enhanced)
bridge.send("user:login", { username: "john" });

// Requests will automatically retry, queue, and log
const result = await bridge.request("data:fetch", { id: 123 });

Multi-Window Isolation

In environments with multiple iframes, enable multi-window isolation:

// Parent window A
const bridgeA = createBridge(iframeA, {
  enableMultiWindow: true,
  windowId: "window-A",
});

// Parent window B
const bridgeB = createBridge(iframeB, {
  enableMultiWindow: true,
  windowId: "window-B",
});

// Now messages between the two windows won't interfere

Type Safety

// Define your message types
interface MyMessages {
  "user:login": { username: string; password: string };
  "user:logout": { userId: string };
  "data:update": { id: number; data: any };
}

// Use generics for type hints
bridge.send<MyMessages["user:login"]>("user:login", {
  username: "john",
  password: "secret",
});

// Request/response also supports generics
const result = await bridge.request<
  MyMessages["data:update"],
  { success: boolean; id: number }
>("data:update", {
  id: 1,
  data: { name: "Updated Name" },
});

Available Plugins

Logger Plugin

// Automatically log all communication messages
const bridge = createBridge(iframe, {
  plugins: {
    logger: {
      level: "debug", // debug, info, warn, error
      colors: true,
      timestamp: true,
    },
  },
});

Retry Plugin

// Automatically retry failed requests
const bridge = createBridge(iframe, {
  plugins: {
    retry: {
      maxRetries: 3,
      backoff: "exponential", // linear, exponential
      retryCondition: (error) => error.message.includes("timeout"),
    },
  },
});

Queue Plugin

// Batch process messages with priority support
const bridge = createBridge(iframe, {
  plugins: {
    queue: {
      maxSize: 100,
      batchSize: 10,
      flushInterval: 1000,
      priority: true,
    },
  },
});

Configuration Options

interface BridgeConfig {
  targetOrigin?: string; // Target origin, default '*'
  timeout?: number; // Request timeout, default 5000ms
  debug?: boolean; // Debug mode, default false
  enableMultiWindow?: boolean; // Enable multi-window isolation, default false
  windowId?: string; // Custom window ID
  plugins?: {
    logger?: boolean | LoggerOptions;
    retry?: boolean | RetryOptions;
    queue?: boolean | QueueOptions;
  };
}

Examples

Check the examples directory for full examples:

License

MIT