Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

javascript - Catch URL change within site Chrome extension

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?

question from:https://stackoverflow.com/questions/66058224/catch-url-change-within-site-chrome-extension

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
chrome.webRequest.onBeforeRequest.addListener(function (details) {
      // your code
}, { url: stopit });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...