9

我正在尝试拦截 chrome 扩展中的代理授权。按照此处的答案:Chrome 扩展中的域授权并阅读此处的文档,我的代码如下所示:

chrome.webRequest.onAuthRequired.addListener(
    function(details, callbackFn) {
        console.log("onAuthRequired!", details, callbackFn);
        //callback({
        //    authCredentials: {username: "1", password: "__TestUse"}
        //});
    },
    {urls: ["<all_urls>"]}
);

问题是 callbackFn未定义,但应该是一个函数。

任何人都知道为什么 callbackFn 未定义。当我阅读文档时,我做得对..

4

1 回答 1

15

该代码有效,我只是忘记添加另一个参数['asyncBlocking']。这段代码工作得很好:

chrome.webRequest.onAuthRequired.addListener(
    function(details, callbackFn) {
        console.log("onAuthRequired!", details, callbackFn);
        callbackFn({
            authCredentials: {username: "1", password: "__TestUser"}
        });
    },
    {urls: ["<all_urls>"]},
    ['asyncBlocking']
);
于 2013-05-17T15:43:08.940 回答