1

我现在需要将我的扩展更新到清单版本 2.0。当我使用webRequestAPI 时,我需要将其更改为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://*/*"
],

一切运行。但是,我不认为这是正确的工作方式。如果我只需要使用单个页面或域,我是否应该请求所有站点的许可?

4

1 回答 1

0

我知道这个问题。

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

致敬。

于 2016-12-27T17:22:18.233 回答