I am trying to get my Chrome Extension to run the function init()
whenever a new page is loaded, but I am having trouble trying to understand how to do this. From what I understand, I need to do the following in background.html:
- Use
chrome.tabs.onUpdated.addListener()
to check when the page is
changed - Use
chrome.tabs.executeScript
to run a script.
This is the code I have:
//background.html
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
chrome.tabs.executeScript(null, {code:init();});
});
//script.js
function init() {
alert(It works!);
}
I am also wondering if the init() function will have access to my other functions located in other JS files?