5美刀 2024-12-04 09:20 采纳率: 25%
浏览 4
已结题

谷歌浏览器插件扩展程序

//创建连接
function connectToProxy() {
    //定义代理参数
    const config= {
        mode: "fixed_servers",
        rules: {
            singleProxy: {
                scheme: "socks5",
                host: 'localhost',
                port: 2335
            },
            bypassList: [
                "192.168.0.0/16"
            ]
        }
    };
    //定义认证密码
    function callbackAuth() {
        return {
            authCredentials: {
                username: "username",
                password: "password",
            }
        };
    }
    //设置代理生效
    chrome.proxy.settings.set(
        { value: config, scope: 'regular' },
        () => {
            if (chrome.runtime.lastError) {
                console.error("代理设置错误:", chrome.runtime.lastError.message);
            } else {
                console.log("代理已连接成功!");
            }
        }
    );

    chrome.webRequest.onAuthRequired.addListener(
        callbackAuth,
        {urls: ["<all_urls>"]},
        ['blocking']
    );
}
如上部分代码,我希望代理socks5连接,但是我并没有成功认证,如果代码有问题请帮我指出。不胜感激。
  • 写回答

1条回答 默认 最新

  • 5美刀 2024-12-04 09:34
    关注

    查阅了google的api并没有找到支持认证的依据。暂时在客户端使用127.0.0.1:2334来支持使用

    评论

报告相同问题?

问题事件

  • 系统已结题 12月12日
  • 创建了问题 12月4日