我正在为 chrome 浏览器开发代理扩展。我的扩展使用以下方式设置浏览器的代理配置:
chrome.proxy.settings.set({
value: config,
scope: 'regular',
});
其中 config 使用fixed_servers
模式。
代理服务器需要身份验证,因此我有:
chrome.webRequest.onAuthRequired.addListener(details => {
// Some logic
return {
authCredentials: {
username: usernameValue,
password: passwordValue,
},
};
});
直到最新的第 71 个 Chrome 版本,这个逻辑都按预期工作:
Browser boots > extensions initialized > all traffic goes through proxy and auth requests from proxy server are handled by listener
.
从第 71 版开始,浏览器似乎不会等待扩展被初始化(在硬退出后出现问题,即使用command + Q
)并开始发送请求。由于代理配置已经设置:
Requests go through proxy > proxy server requests authentication > extension is still not initialized by browser, therefore auth request listener is not added in the background as well - since there is nothing to intercept auth requests - native auth prompt is sown for the user
.
当扩展被初始化时,这最终会导致非常糟糕的 UX + 片刻,侦听器已经到位,因此用户可以填写提示并提交,或者简单地取消 - 无论如何代理及其身份验证都有效。
我正在寻找这种情况的解决方案。也许有一种方法可以为浏览器设置一些配置,以防止它在初始化某些扩展之前执行请求,或者在浏览器退出之前暂停/重置/清除代理配置(然后我可以在初始化时再次手动设置代理)。或针对给定情况的任何其他修复。
我已经尝试过使用我们的chrome.windows
方法来监视何时创建和删除浏览器窗口,并在最后一个被删除时尝试调用chrome.proxy.settings.clear({ scope: 'regular' }, function() {...});
,但正如我所想的那样,只能sync
在退出之前发生,而async
不要,因此chrome.proxy.settings.clear()
没有用。
我提前感谢任何提示、建议、解决方案/黑客等。