当我尝试运行chrome.webRequest.onHeadersReceived
时,我遇到了这个问题。
这是我的代码:
的manifest.json
{
"manifest_version": 2,
"name": "testing",
"description": "testing",
"version": "1.0",
"permissions":
[
"webRequest","*://*/*","webRequestBlocking"
],
"content_scripts":
[
{
"matches": ["*://*/*"],
"css": ["highlight.css"],
"js": ["highlight.js","jquery-min.js" ],
"run_at": "document_end",
"all_frames": true
}
]}
highlight.js
chrome.webRequest.onHeadersReceived.addListener(
function(info) {
var headers = info.responseHeaders;
for (var i=headers.length-1; i>=0; --i) {
var header = headers[i].name.toLowerCase();
if (header == 'x-frame-options' || header == 'frame-options') {
headers.splice(i, 1); // Remove header
}
}
return {responseHeaders: headers};
},
{
urls: [ '*://*/*' ], // Pattern to match all http(s) pages
types: [ 'sub_frame' ]
},
['blocking', 'responseHeaders']
);
当我运行脚本时,我收到如下错误:
chrome.webRequest不可用:您无权访问此API。确保manifest.json中包含所需的权限或清单属性 未捕获的TypeError:无法读取未定义的属性'onHeadersReceived'
对此有何想法?我尝试在之前的帖子中应用解决方案,但没有工作。