javascript - 设置 chrome 代理设置表单扩展
问题描述
我为代理服务器开发了一个 chrome 扩展。在将 IP 和 PORT 设置为 chrome 设置后,我通过 API 获取服务器(及其授权数据)列表:
connect: function(proxyData, callback) {
this.setListener(proxyData);
chrome.proxy.settings.set(
{
value: {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: proxyData.ip,
port: parseInt(proxyData.port)
},
}
},
scope: 'regular'
},
function() {
if (typeof callback === 'function') {
callback(proxyData);
}
}
);
}
之后我添加了自动化监听器:
setListener: function(proxyData) {
let username = proxyData.username,
password = proxyData.password;
this.proxyAuthFunction = function(details, callbackFn) {
console.log(username, password, 'Init proxy auth function');
callbackFn({authCredentials: { username: username, password: password}});
};
if (chrome.webRequest.onAuthRequired.hasListener(this.proxyAuthFunction)) {
chrome.webRequest.onAuthRequired.removeListener(this.proxyAuthFunction);
}
chrome.webRequest.onAuthRequired.addListener(
this.proxyAuthFunction,
{urls: ["<all_urls>"]},
["asyncBlocking"]
);
}
它不起作用,浏览器无论如何都会要求基本授权。
但是硬编码效果很好,浏览器不要求基本授权:
setListener: function(proxyData) {
let username = 'qwerty',
password = 'qwerty';
this.proxyAuthFunction = function(details, callbackFn) {
console.log(username, password, 'Init proxy auth function');
callbackFn({authCredentials: { username: username, password: password}});
};
if (chrome.webRequest.onAuthRequired.hasListener(this.proxyAuthFunction)) {
chrome.webRequest.onAuthRequired.removeListener(this.proxyAuthFunction);
}
chrome.webRequest.onAuthRequired.addListener(
this.proxyAuthFunction,
{urls: ["<all_urls>"]},
["asyncBlocking"]
);
}
有没有人遇到过类似的问题?
解决方案
推荐阅读
- flutter - 颤振器PixelRatio
- spring - Spring MongoDB:投影数组字段大小(如果存在)
- c# - iText7 & C# 从存储在 MSSQL DB 中的 PDF 中提取页面
- zurb-foundation - 为什么不遵守电子邮件输入的错误消息?
- javascript - NestJS:ValidationPipe 不适用于路由@Param
- python - 动态创建对象又名将字符串转换为python中的类名调用
- python - Python async unitest - 断言 False 不会通过测试
- javascript - 写入时验证输入字段
- thrift - TThreadPoolServer 使用示例
- python - 如何在 Python 中导入 .pyx 文件?