0
我想让我的后台页面观看URL并在某些URL上调用chrome.tabs.executeScript。我应该调用哪种API来以这种方式观看URL?基于URL注入Chrome浏览器扩展内容脚本
我想让我的后台页面观看URL并在某些URL上调用chrome.tabs.executeScript。我应该调用哪种API来以这种方式观看URL?基于URL注入Chrome浏览器扩展内容脚本
chrome.tabs.onUpdated.addListener
可用于检测tab负载。这不会框架内检测导航虽然:
chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
if (info.status === 'complete' && /some_reg_ex_pattern/.test(tab.url)) {
// ...
}
});
为此,你最好使用内容脚本,与all_frames
set to true。在内容脚本中,您可以使用this answer中所述的方法注入代码。然后使用该页面的location
对象来过滤URL。