[英]How do I intercept and modify HTTP Auth requests from a Chrome extension?
Based on the documentation I have written the following code as a background script: 根据文档,我编写了以下代码作为后台脚本:
chrome.webRequest.onAuthRequired.addListener(
function (details, callback) {
console.log('onAuthRequired', details);
callback({
authCredentials: {username: "alpha", password: "beta"}
});
},
{urls: ['<all_urls>']},
['asyncBlocking']
);
chrome.webRequest.onBeforeRequest.addListener(
function(details, callback) {
console.log('onBeforeRequest', details);
},
{urls: ['<all_urls>']}
);
The onBeforeRequest
callback works, but the onAuthRequired
callback does not. onBeforeRequest
回调有效,但onAuthRequired
回调无效。 I do not seem to get 'onBeforeRequest'
printed to the console as I expect. 我似乎并没有像预期的那样将
'onBeforeRequest'
打印到控制台。 What is missing? 什么东西少了?
My intention is simply to automatically provide auth credentials for a specific domain. 我的意图仅仅是为特定域自动提供身份验证凭据。 A working example of this would suffice as an answer.
一个可行的例子就可以作为答案。
您的代码看起来不错,但你需要使用webRequestBlocking
的权限除了普通webRequest
许可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.