chrome.webRequest.onAuthRequired Listener

2020-03-15 02:13发布

i'm trying to intercept the proxy authorization inside a chrome extension. Following the answer to here: Domain Authorization in Chrome Extension and reading the docs here my code looks like this:

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

The problem is that callbackFn is undefined but should be a function.

Anyone got some ideas why callbackFn is undefined. As I read the docs I'm doing it right ..

1条回答
forever°为你锁心
2楼-- · 2020-03-15 02:59

The code works, I just forgot to add another parameter ['asyncBlocking']. This code works just fine:

chrome.webRequest.onAuthRequired.addListener(
    function(details, callbackFn) {
        console.log("onAuthRequired!", details, callbackFn);
        callbackFn({
            authCredentials: {username: "1", password: "__TestUser"}
        });
    },
    {urls: ["<all_urls>"]},
    ['asyncBlocking']
);
查看更多
登录 后发表回答