I have a script which I want to inject to a page every 10 seconds. I use this code:
chrome.tabs.onUpdated.addListener(function(tabId,tab){
chrome.tabs.executeScript(null,{file:"program.js"});
}
);
program.js looks like this:
$("body").prepend("Hello World!");
setTimeout(function(){location.reload();},10000);
Meaning every 10 seconds the page should refresh itself and inject this piece of code, it works ok, but sometimes (especially when running more than one tab) I get this error:
Uncaught TypeError: Cannot read property 'onUpdated' of undefined
I'm guessing its not getting the tabId or something.
But I can't solve it.
Help would be very much appreciated.
I came across the same problem only with chrome.runtime.onMessageExternal.addListener
and chrome would complain about onMessageExternal
. Like @scott-f pointed out the reason for this bug is 'abusing' th reload button. I removed and reinstalled the extension and it worked.
In hindsight I would suggest you use the --load-extensions='extension/path'
from the cli to test your extension with the mouse just to avoid the overhead of navigating around chrome's menus, and use Selenium to automate your tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With