In our firefox extension from the background script, we are checking the currently loading tab and check whether the URL is our desired URL if it is our desired URL then we are executing a javascript file on the tab with the help of browser.tabs.onupdated event using browser.tabs.executeScript and the file is executed successfully but the window.onload event present on the content script doesn't execute but the console statement on the first line executed in the content script
Background.js
browser.tabs.onUpdated.addListener(
function (tabId, changeInfo, tab) {
// here checking wether to execute the script for the currently loading tab based on the URL of tab
browser.tabs.executeScript(tab.id, { file: "jquery.min.js" });
browser.tabs.executeScript(tab.id, { file: "automate.js" });
},
{ properties: ["status"] }
);
automate.js
console.log("automate.js executing");
window.addEventListener("load",function(){
// this console.log statement not printed
console.log("window is loaded");
})