且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

基于URL注入Chrome浏览器扩展内容脚本

更新时间:2023-12-05 11:41:34

chrome.tabs.onUpdated.addListener can be used to detect tab loads. This will not detect navigation within frames though:

chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
   if (info.status === 'complete' && /some_reg_ex_pattern/.test(tab.url)) {
       // ...
   }
});

For this purpose, you'd better use a content script, with all_frames set to true. Within the content script, you can inject code using the methods as described in this answer. Then use the page's location object to filter URLs.