Open prbaron opened 7 years ago
I realise it is quite opinionated in the way that it does not return a status but it will provide an error if the plugin is not installed and enabled.
Another solution could be
window.getChromeExtensionStatus = function(callback) {
// for Firefox:
if (!!navigator.mozGetUserMedia) {
callback(null, 'not-chrome');
return;
}
window.addEventListener('message', onIFrameCallback);
function onIFrameCallback(event) {
if (!event.data) return;
if (event.data.chromeExtensionStatus) {
callback(null, event.data.chromeExtensionStatus);
}
// this event listener is no more needed
window.removeEventListener('message', onIFrameCallback);
}
setTimeout(postGetChromeExtensionStatusMessage, 100);
};
According to NodeJS conventions, the callback should be error-first, meaning
getChromeExtensionStatus()
should return a callback with an error as the first value and the status as the second value.I am using Bluebird's promisify function with
getChromeExtensionStatus()
and I have to use.catch
because of that.here is my suggestion