I made a Chrome extension to do some routine tasks that I have to do as checking some values and clicking some buttons. It works really well when it's on focused tab but it stops working when it is in background or not focused.
My background.js:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.status == 'complete') {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
//checking something
chrome.tabs.query({currentWindow: true, active: true},
function(tabs) {
chrome.tabs.sendMessage(tab.id, {type: 1});
});
});
}
});
My content.js:
chrome.runtime.onMessage.addListener(function(request, sender, response) {
if(request.type == 1) {
//actions
}
});
I don't really know what I can do to let this works in background too. Thanks for the help