我在尝试运行时遇到了这个问题chrome.webRequest.onHeadersReceived
。
这是我的代码:
清单.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
}
]}
突出显示.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 中包含所需的权限或清单属性。
未捕获的类型错误:无法读取未定义的属性“onHeadersReceived”
对此有任何想法吗?我尝试在上一篇文章中应用解决方案,但没有奏效。