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

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.).

Answers:

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.