根据文档,我编写了以下代码作为后台脚本:
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>']}
);
回调有效,onBeforeRequest
但onAuthRequired
回调无效。我似乎没有'onBeforeRequest'
按预期打印到控制台。什么不见了?
我的意图只是自动为特定域提供身份验证凭据。一个可行的例子就足以作为答案。