chrome-bus
Share an event emitter among chrome runtime components
Because managing anonymous events is not fun
This module is used by chromiumify
install
$ npm install chrome-bus
usage
basic
This usage is when you have a background page that you want to communicate to.
var createBus = require('chrome-bus')
var bus = createBus()
bus.on('hello', function (msg) {
console.log('msg=', msg)
})
bus.emit('hello', Date.now())
webview
Communicating with webviews in chrome apps is not straight forward as a channel between the host page and the view needs to be created.
There is also no way for a page to know if it is being hosted in a webview.
So there are conventions for working around this.
Below are the main parts you need to understand but see the sample app for a working sample
host page
var view = document.getElementById('wv')
view.addEventListener('contentload', function (evt) {
var wvbus = createBus(view)
wvbus.on('goodbye', function (msg) {
assert.ok('Message Received')
console.log('msg=', msg)
})
wvbus.emit('hello', Date.now())
})
In the HTML for the view ensure that the URI to the location of the view contains a bookmark to fragment
<webview src="webview.html#fragment" id="wv" partition="wvevent" autosize="true" minwidth="500" minheight="450"></webview>
webview page
var bus = createBus()
bus.on('hello', function (msg) {
assert.ok('Message Received')
console.log('msg=', msg)
bus.emit('goodbye', Date.now())
})