I'm trying to send a message to the active tab in Chrome
function sendMessageToCurrentTab(){
var args = Array.prototype.slice.call(arguments); //Get arguments as an array
if(typeof browser !== 'object' || typeof args[args.length - 1] === 'function') {
//Either is Chrome, or we have a callback function
chrome.tabs.query({active:true,currentWindow:true},function(tabs){
args.unshift(tabs[0].id); //Add tab ID to be the new first argument.
chrome.tabs.sendMessage.apply(this,args);
});
return;
}//else
return browser.tabs.query({active:true,currentWindow:true}).then(function(tabs){
args.unshift(tabs[0].id); //Add tab ID to be the new first argument.
return browser.tabs.sendMessage.apply(this,args);
});
}
chrome.runtime.onMessage.addListener((command) => {
chrome.tabs.executeScript({
file:'core.js'
}, function(){
sendMessageToCurrentTab("test");
});
});
but it doesn't seem to be working. Why? In Firefox it worked, but I changed the event listener to the chrome.runtime.onMessage.addListener
here to make it working, so that's probably the problem, but with what should I change it?