Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

javascript - chrome.webRequest.onAuthRequired Listener

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 ..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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']
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...