Tabs Intercom


Tabs Intercom is a tiny utility library that lets you register a function in one browser tab and invoke it (with params) from another tab. It does away with manual event setup and boilerplate inter-tab messaging, making cross-tab communication seamless in web apps.

See @simplemented/tabs-intercom (NPM) for more details.

How it works

Under the hood, Tabs Intercom leverages localStorage storage events to broadcast invocation messages. You register handlers in each tab context and then call them from any tab. The library handles marshaling of arguments and routing to the right handler via the storage-based event bus.

The typical API usage looks like:

import TabsIntercom from '@simplemented/tabs-intercom';

const intercom = new TabsIntercom();

function logOut(userId: string) { /* … */ }

const logOutEverywhere = intercom.register(logOut);

logOutEverywhere('42'); // called in every tab or window

You can register multiple names, pass serializable arguments, and handle return values (as a promise). The library abstracts away the event wiring and ensures cross-tab calls “just work”.

Key features

  • Minimal dependencies and runtime overhead — no dependencies, null, nada;
  • Zero boilerplate APIregister(fn) → callable broadcast proxy;
  • Simple API — just one register method converting your callback to call-everywhere function, with optional unregister;
  • Type inference preserved for params — works with JSON-serializable data.

Learnings & challenges

  • Serializing and deserializing function arguments and return data;
  • Dealing with edge cases: same tab calling itself, no handler present, error propagation;
  • Balancing simplicity vs. flexibility (e.g., timeouts, retry, acknowledgments).

Tech stack

  • TSDX — Zero-config CLI for TypeScript package development;
  • Browser APIs (localStorage + storage events).

Roadmap

  • Async callbacks support;
  • Timeout & error propagation;
  • Message queuing for tabs that weren’t yet ready;