//创建连接
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连接,但是我并没有成功认证,如果代码有问题请帮我指出。不胜感激。