chrome.webRequest.onAuthRequired监听器 [英] chrome.webRequest.onAuthRequired Listener

查看:972
本文介绍了chrome.webRequest.onAuthRequired监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Chrome扩展中截取代理授权。
按照以下答案: Chrome扩展程序中的域授权并阅读docs here 我的代码如下所示:

  chrome.webRequest.onAuthRequired.addListener(
function(details,callbackFn){
console.log(onAuthRequired!,详细信息,callbackFn);
//回调({
// authCredentials:{username:1,password:__TestUse}
//});
},
{url:[< all_urls>]}
);

问题在于callbackFn是 undefined ,但应该是一个函数。 / p>

任何人都有一些想法,为什么callbackFn是未定义的。当我阅读文档时,我做的是正确的。

解决方案

代码工作正常,我忘记添加另一个参数 [ 'asyncBlocking']
这段代码工作的很好:

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


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

解决方案

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

这篇关于chrome.webRequest.onAuthRequired监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆