1

请问,是否可以通过 Google Chrome 扩展程序获取 HTTP auth 登录用户的用户名?权限没问题,我都可以设置。

谢谢!

http://code.google.com/chrome/extensions/devguide.html

4

1 回答 1

1

您可以使用webRequest API为您查看标头。Authorization下面是一些示例代码,它从所有 HTTP 请求的标头中解析出 base64 编码的用户名和密码:

chrome.webRequest.onSendHeaders.addListener(function(details) {
    console.log(details.url, details.requestHeaders);
    for(var i = 0; i < details.requestHeaders.length; ++i) {
        var header = details.requestHeaders[i];
        if(header.name == "Authorization") {
            // this is my quick effort for parsing the auth value
            // formatted like "Basic [base64 of 'user:pass']"
            var b64val = header.value.split(" ")[1];
            var credArray = atob(b64val).split(":");
            var user = credArray[0];
            var pass = credArray[1];

            // now do something with user/pass
        }
    }
},
{"urls":["*://*/*"]},
["requestHeaders"]);
于 2012-05-03T17:34:15.603 回答