簡體   English   中英

如何攔截和修改來自Chrome擴展程序的HTTP身份驗證請求?

[英]How do I intercept and modify HTTP Auth requests from a Chrome extension?

根據文檔,我編寫了以下代碼作為后台腳本:

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'打印到控制台。 什么東西少了?

我的意圖僅僅是為特定域自動提供身份驗證憑據。 一個可行的例子就可以作為答案。

您的代碼看起來不錯,但你需要使用webRequestBlocking的權限除了普通webRequest許可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM