declarativeWebRequest和主机规则

时间:2013-06-27 15:41:10

标签: google-chrome google-chrome-extension

我现在需要将扩展​​程序更新为清单版本2.0。当我使用webRequest API时,我需要将其更改为declarativeWebRequest

问题是我的权限有问题。

To execute the action "declarativeWebRequest.SetRequestHeader",
you need to request host permission for all hosts.

我的清单看起来像:

"permissions": [
    "declarativeWebRequest",
    "https://example.com/default.dll"
],
"background": {
    "scripts": ["background.js"],
    "persistent": false
}

我的背景页面如下:

var request_matcher = new chrome.declarativeWebRequest.RequestMatcher({
    url: {
        urlEquals: "https://example.com/default.dll"
    },
    resourceType: ["main_frame"],
    stages: ['onBeforeSendHeaders']
});
var request_rule = {
    conditions: [request_matcher],
    actions: [
        new chrome.declarativeWebRequest.SetRequestHeader({
            name: "User-Agent",
            value: "New user agent "
        })
    ]
};
chrome.declarativeWebRequest.onRequest.addRules([
    request_rule
]);

如果我将权限更改为:

"permissions": [
    "declarativeWebRequest",
    "https://*/*"
],

一切都在运行。但是,我不相信这是正确的工作方式。如果我只需要使用单个页面或域名,我是否应该同意所有网站的许可?

1 个答案:

答案 0 :(得分:0)

我知道这个问题。

.env

萨吕。