1

I'd like to have my background page watch the URL and call chrome.tabs.executeScript on certain URLs. What API should I call to watch the URL in such a manner?

Ben McCann
  • 18,548
  • 25
  • 83
  • 101

1 Answers1

4

chrome.tabs.onUpdated.addListener can be used to detect tab loads. This will not detect navigation within frames though:

chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
   if (info.status === 'complete' && /some_reg_ex_pattern/.test(tab.url)) {
       // ...
   }
});

For this purpose, you'd better use a content script, with all_frames set to true. Within the content script, you can inject code using the methods as described in this answer. Then use the page's location object to filter URLs.

Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678