How to get content script run on page's update and url's change?

北城余情 提交于 2020-01-03 00:53:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!