0

I would like to intercept the user whenever they enter a page with a URL that contains a certain RegEx. Right now, on a background script, I can use:

chrome.webNavigation.onBeforeNavigate.addListener(function (details) {
    chrome.tabs.update(details.tabId,{url: chrome.extension.getURL('popup.html')}, undefined);
}, { url: stopit });

Where the array stopit holds JSON objects all of the form:

{urlContains: "regex.x"}

This works great when the user navigates to a new site and uses the bar at the top of the browser. What this DOESN'T cover is when a user navigates to a new page within the same site. Say, for example, the user loads up the reddit home page with the url bar. When they go to subreddits, the url changes and may now contain the Regex. How would I go about checking the url on such an event?

Inaudible Jive
  • 139
  • 2
  • 8
  • is that ? https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onBeforeRequest – Daniil Loban Feb 05 '21 at 05:56
  • The new reddit site is a SPA (Single Page Application) so you need a different event e.g. onHistoryStateUpdated, see also [this answer](https://stackoverflow.com/a/39508954). – wOxxOm Feb 05 '21 at 08:49

1 Answers1

0
chrome.webRequest.onBeforeRequest.addListener(function (details) {
      // your code
}, { url: stopit });
Daniil Loban
  • 4,165
  • 1
  • 14
  • 20