Google chrome extension 使用Chrome Extensions中的add listener更改/向http请求添加更多内容

Google chrome extension 使用Chrome Extensions中的add listener更改/向http请求添加更多内容,google-chrome-extension,Google Chrome Extension,我一直在尝试在每个URL中添加一些以某个特定URL开头的内容,是否可以在Chrome中这样做 我一直在尝试使用chrome.webRequest.onCompleted,但在文档中看不到任何内容 您可以读取或更改响应 chrome.webRequest.onCompleted.addListener(function(info) { if(info.url.indexOf('mypage.com/page') > -1){ //Do Something here

我一直在尝试在每个URL中添加一些以某个特定URL开头的内容,是否可以在Chrome中这样做

我一直在尝试使用
chrome.webRequest.onCompleted
,但在文档中看不到任何内容

您可以读取或更改响应

chrome.webRequest.onCompleted.addListener(function(info) { 
    if(info.url.indexOf('mypage.com/page') > -1){
       //Do Something here to alter the response before its used in Chrome requests
       //or displayed 
    }

},{urls:["<all_urls>"]});
chrome.webRequest.onCompleted.addListener(函数(信息){
if(info.url.indexOf('mypage.com/page')>-1){
//在Chrome请求中使用响应之前,请在此处执行一些更改
//或显示
}
},{url:[“”]});
如何更改此内容?在将其放入选项卡或iframe之前向其添加更多内容

谢谢

A正是你想要的。内容脚本被注入到浏览器访问的每个页面中,并可用于更改页面的HTML

您可以在清单中使用
matches
属性(或
include\u globs
属性以实现更大的控制)来控制将脚本注入哪些页面

您的清单应该如下所示:

{
    "name": "My extension",
     ...
    "content_scripts": [
        {
             "matches": ["*://*.mypage.com/page/*"],
             "js": ["jquery.js", "myscript.js"],
             "run_at": "document_idle"
        }
    ],
    ...
}
run_at
属性指定应该何时注入脚本;有关详细信息,请参阅链接的Chrome文档。

A正是您想要的。内容脚本被注入到浏览器访问的每个页面中,并可用于更改页面的HTML

您可以在清单中使用
matches
属性(或
include\u globs
属性以实现更大的控制)来控制将脚本注入哪些页面

您的清单应该如下所示:

{
    "name": "My extension",
     ...
    "content_scripts": [
        {
             "matches": ["*://*.mypage.com/page/*"],
             "js": ["jquery.js", "myscript.js"],
             "run_at": "document_idle"
        }
    ],
    ...
}

run_at
属性指定应该何时注入脚本;有关详细信息,请参阅链接的Chrome文档。

这可能会有帮助:澄清:您想更改页面本身(例如,添加一些HTML),还是只重定向URL?可能会有帮助:澄清:您想更改页面本身(例如,添加一些HTML),还是只重定向URL?