I'm trying to communicate between main.js and a content script. Here is my main.js:
var pageMod = require('sdk/page-mod');
var self = require('sdk/self');
var ss = require('sdk/simple-storage');
pageMod.PageMod({
include: 'example.com',
contentScriptFile: self.data.url('content-script.js'),
onAttach: function(worker) {
worker.port.on('getSetting', function(request) {
// var settingValue = ss.storage[request]
var settingValue = 'test value'; // for testing, return an
// arbitrary string
worker.port.emit('settingRetrieved', settingValue);
});
}
});
And content-script.js:
alert('getting setting...');
self.port.emit('getSetting', 'test setting name');
alert('asked for setting...');
self.port.on('settingRetrieved', function(results) {
alert('retrieved setting: "' + results + '"');
});
It appears that self.port.on() in content-script.js is not receiving the message from main.js. What am I doing wrong?