Simple RPC for iframes, workers, tabs, and AI-powered apps. Zero dependencies. Fast. Secure by default.
7 transport types, security defaults, agent-ready docs, and a plugin ecosystem out of the box.
createSecure() enforces best practices. Dev warnings catch insecure configs. AES-256-GCM encryption built-in.
~170M ops/sec emitSync. Competitive with nanoevents on emit workloads. Zero runtime overhead.
Optimized for AI agent usage. llms.txt + GEMINI.md docs. Schema validation. Copy-paste patterns for agents.
PostMessage, BroadcastChannel, SharedWorker, ServiceWorker, WebSocket, NativeBridge, MessageChannel.
Retry, Circuit Breaker, Rate Limiter, Compression, Batching, Encryption. All tree-shakeable.
Distributed tracing, Prometheus metrics, backpressure control, message versioning with migration.
Connect any iframe to your main page with secure RPC in under 30 seconds.
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' }
);
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 }
);
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() | ✓ | ✗ | ✗ | ✗ |
Install CrossBus and start building secure cross-context applications.
npm install crossbus