You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome扩展代理认证时onAuthRequired事件未触发的问题求助

Chrome扩展代理认证时onAuthRequired事件未触发的问题求助

我正在开发一个Chrome扩展的代理功能,目前代理能正常连接使用,但每次都需要手动输入代理的认证凭据,体验实在不太好。

我尝试用webRequest和webRequestAuthProvider来实现自动填充代理认证信息的功能,写了以下代码:

let authListener = function(details, callbackFn) {
    console.log('Auth required for', details.url);
    callbackFn({
        authCredentials: {
            username: 'username',
            password: 'pass',
        }
    });
}

chrome.webRequest.onAuthRequired.addListener(
    authListener,
    { urls: ["<all_urls>"] }
    ['asyncBlocking']
);

但现在遇到了棘手的问题:当浏览器弹出代理认证的弹窗时,chrome.webRequest.onAuthRequired这个事件从来不会被触发,不过像chrome.webRequest.onBeforeRequest或者chrome.webRequest.onCompleted这类webRequest的其他事件都能正常触发,这就让我摸不着头脑了。

我的扩展权限配置如下:

"permissions": ["storage", "alarms", "tabs", "proxy", "webRequest", "webRequestAuthProvider"],

代理连接的函数代码是这样的:

export function proxyConnect(proxy, scheme = 'http') {
    chrome.proxy.settings.set(
        {
            value: {
                mode: "fixed_servers",
                rules: {
                    singleProxy: {
                        scheme,
                        host: proxy.host,
                        port: proxy.port
                    },
                    bypassList: ['https://2ip.io'] // "<all_urls>"
                }
            },
            scope: 'regular'
        },
    );
}

有没有大佬能帮我排查下问题?为什么onAuthRequired事件就是不触发呢?

备注:内容来源于stack exchange,提问作者yur0n

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:34:51