Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including page-bus with all npm packages installed. Try it out:

var pageBus = require("page-bus")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

page-bus v3.0.1

share an event emitter among pages and frames on the same domain

page-bus

share an event emitter among pages and frames on the same domain

This module works offline and does not rely on any network IO.

Behind the scenes, the localStorage API and the window 'storage' event is used to synchronize cross-page events.

Previously this module used a shared worker, but shared workers need to elect a master for the URL.createObjectURL() api which got very complicated.

example

Just create a bus, which returns an event emitter:

var createBus = require('page-bus');
var bus = createBus();

bus.on('hello', function (msg) {
    console.log('msg=', msg);
});

bus.emit('hello', Date.now());

Compile with browserify then open this page up on a few tabs.

The messages get shared hooray!

Check out the demo on neocities.

methods

var createBus = require('page-bus')

var bus = createBus(opts)

Create a new event emitter bus.

  • opts.key - the string key to save data. default: 'page-bus'. By using a different value, you can create namespaces.

All other pages on the same domain in the same browser will be able to open the event emitter.

install

With npm do:

npm install page-bus

license

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free