This repository was archived by the owner on Mar 11, 2019. It is now read-only.

Description
There is a problem with access to window.* properties inside message listener's callback in Firefox with kango 1.8.0. This problem doesn't occur in kango 1.7.9.
For example, if I do in content-script:
kango.addMessageListener('msg', function() {
document.querySelectorAll('input');
});
and in background-script:
tab.dispatchMessage('msg');
I'll get a message from Firefox:
Error: Permission denied to access property "document"
I solved this problem by calling a callback in Promise:
// Custom message listener
'use strict';
function MessageListener() {
this.addedListeners = new Map();
}
MessageListener.prototype.add = function (message, callback) {
const isFirefox = typeof InstallTrigger !== 'undefined';
let adaptedCallback = callback;
if(isFirefox) {
adaptedCallback = runAsync.bind(null, callback)
}
kango.addMessageListener(message, adaptedCallback)
this.addedListeners.set(callback, adaptedCallback);
};
MessageListener.prototype.remove = function (message, callback) {
const adaptedCallback = this.addedListeners.get(callback);
kango.removeMessageListener(message, adaptedCallback);
this.addedListeners.delete(callback);
};
module.exports = MessageListener;
function runAsync(callback, event) {
new Promise(resolve => {
callback(event);
resolve();
}).catch(e => console.log(e));
}