My content script runs only on one domain. But if I use only one tab, content script runs only 1 time. I want my script to run on every new request (page reload and URL changes for example from bla.com/home to bla.com/servoce etc.).
Asked
Active
Viewed 4,179 times
3
-
2Is the site using the history API for navigation? If so, then take a look at https://stackoverflow.com/questions/18397962/chrome-extension-is-not-loading-on-browser-navigation-at-youtube. – Rob W Jul 21 '15 at 15:17
-
1By default, content scripts do run on page updates and url changes. The difficulty is when that update or change is abnormal (e.g., the history api). So the answer to your question is "that already happens". – Teepeemm Jul 22 '15 at 18:29
1 Answers
1
The content script can listen for page changes. There's a few ways to do this, but my guess is you want the onUpdated event in chrome.tabs:
chrome.tabs.onUpdated.addListener(function callback)
There's more details on this here: https://developer.chrome.com/extensions/tabs
There is also a listener for web requests in the chrome.webRequest api that might work:
chrome.webRequest.onBeforeRequest.addListener(function callback)
For this option, you'd have to detect if the request will cause a redirect or not.
Either option should allow you to call some javascript on redirect.

Brian
- 1,513
- 2
- 14
- 17
-
"chrome.tabs.onUpdated.addListener(function callback)" this code works only when page updated by browser's update button but do not work when I change URL. My script works onle 1 time!!! – user3528865 Jul 21 '15 at 19:46