Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome-extension "Cannot read property 'onUpdated' of undefined"

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.

like image 208
Nir Tzezana Avatar asked Nov 11 '22 05:11

Nir Tzezana


1 Answers

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.

like image 163
fakedrake Avatar answered Nov 14 '22 23:11

fakedrake