问题
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.).
回答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.
来源:https://stackoverflow.com/questions/31542371/how-to-get-content-script-run-on-pages-update-and-urls-change