v0.1.0 — Cross-Context Messaging for Browsers

Stop wrestling with
postMessage.

Simple RPC for iframes, workers, tabs, and AI-powered apps. Zero dependencies. Fast. Secure by default.

~170M
ops/second
0
dependencies
1074
tests passing
15KB
gzipped

Everything you need.

7 transport types, security defaults, agent-ready docs, and a plugin ecosystem out of the box.

🔒

Secure by Default

createSecure() enforces best practices. Dev warnings catch insecure configs. AES-256-GCM encryption built-in.

Fast

~170M ops/sec emitSync. Competitive with nanoevents on emit workloads. Zero runtime overhead.

🤖

Agent-Ready Design

Optimized for AI agent usage. llms.txt + GEMINI.md docs. Schema validation. Copy-paste patterns for agents.

📡

7 Transport Types

PostMessage, BroadcastChannel, SharedWorker, ServiceWorker, WebSocket, NativeBridge, MessageChannel.

🔌

Plugin Ecosystem

Retry, Circuit Breaker, Rate Limiter, Compression, Batching, Encryption. All tree-shakeable.

🏢

Enterprise Ready

Distributed tracing, Prometheus metrics, backpressure control, message versioning with migration.

Two files. That's it.

Connect any iframe to your main page with secure RPC in under 30 seconds.

main.js — Hub (Parent Page)
import { CrossBus } from 'crossbus';

// 1. Create secure hub
const hub = CrossBus.createSecure({
  peerId: 'hub',
  isHub: true,
  allowedOrigins: ['https://yourdomain.com']
});

// 2. Register handlers
hub.handle('getData', async ({ userId }) => {
  return await db.query({ userId });
});

// 3. Connect iframe
hub.addTransport(
  new PostMessageTransport(iframe.contentWindow),
  { peerId: 'agent' }
);
iframe.js — Agent (Child Frame)
import { CrossBus } from 'crossbus';

// 1. Create agent
const agent = new CrossBus({
  peerId: 'agent',
  allowedOrigins: ['*']
});

// 2. Connect to parent
agent.addTransport(
  new PostMessageTransport(window.parent),
  { peerId: 'hub' }
);

// 3. Make RPC calls — that's it!
const user = await agent.request(
  'hub', 'getData', { userId: 123 }
);

Why developers choose CrossBus

Security defaults, agent docs, and features other messaging libraries don't offer.

Feature CrossBus Comlink Penpal Post-Robot
llms.txt + agent.json
createSecure() factory
Handler rate limiting
Schema validation
7 transport types
WebSocket + auto-reconnect
healthCheck() + diagnose()

Ready to build?

Install CrossBus and start building secure cross-context applications.

npm install crossbus
⭐ Star on GitHub Read the Docs →