【发布时间】:2018-08-10 11:24:24
【问题描述】:
我正在为 chrome 开发一个扩展。该扩展允许从列表中选择任何代理服务器,每个代理都需要授权。当用户想要两次连接到同一个代理服务器但使用不同的凭据时会出现问题,例如,如果用户在第一次 chrome 记住它时成功登录,并且当用户尝试使用其他凭据连接时 chrome将使用在第一次登录时输入的凭据。
var authCredentials = {
username: 'Jack',
password: 'PassForJack'
}
var auth = function () {
return {
authCredentials
};
};
chrome.webRequest.onAuthRequired.addListener(auth, {
urls: ["<all_urls>"]
}, ["blocking"]);
// set a new proxy server for the first login
chrome.proxy.settings.set({
value: {
mode: 'fixed_servers',
rules: {
singleProxy: {
host: 'some-proxy-server.com',
port: 8000
}
}
},
scope: 'regular'
});
// change credentails
authCredentials = {
username: 'Bob',
password: 'PassForBob'
};
// remove proxy configuration
chrome.proxy.settings.set({
value: {
mode: 'direct'
},
scope: 'regular'
});
// remove onAuthListener
chrome.webRequest.onAuthRequired.removeListener(auth)
chrome.webRequest.onAuthRequired.hasListener(auth) // returns false
chrome.webRequest.onAuthRequired.addListener(auth, {
urls: ["<all_urls>"]
}, ["blocking"]);
// lets re connect
chrome.proxy.settings.set({
value: {
mode: 'fixed_servers',
rules: {
singleProxy: {
host: 'some-proxy-server.com',
port: 8000
}
}
},
scope: 'regular'
});
// that doesn't help the user would be logged as "Jack" but has to be as "Bob"
【问题讨论】:
-
你能澄清你的问题吗?我不确定应该发生什么与正在发生什么。
标签: javascript google-chrome-extension proxy