javascript - 使用本机消息在 Chrome 中的 NTLM 弹出窗口中填写用户名和密码
问题描述
网站:https ://httpbin.org/basic-auth/user/passwd
当我们访问该站点时,该onAuthRequired
方法在background.js
. 根据 mdn 文档https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onAuthRequiredextraInfoSpec
,我们可以使用as传递用户名和密码字段blocking
。
测试方法:
background.js
const myCredentials = {
username: "me@company.com",
password: "zDR$ERHGDFy"
}
function provideCredentialsSync(requestDetails) {
// If we have seen this request before, then
// assume our credentials were bad, and give up.
if (pendingRequests.indexOf(requestDetails.requestId) != -1) {
console.log(`bad credentials for: ${requestDetails.requestId}`);
return { cancel: true };
}
pendingRequests.push(requestDetails.requestId);
console.log(`providing credentials for: ${requestDetails.requestId}`);
return { authCredentials: myCredentials };
}
browser.webRequest.onAuthRequired.addListener(
provideCredentialsSync,
{ urls: [target] },
["blocking"]
);
参考见github代码:https ://github.com/mdn/webextensions-examples/tree/master/stored-credentials
根据上述方法,它尝试使用给定的凭据进行身份验证。如果凭据正确,则将重定向到相应的页面。
问题
- 如何只填写凭据而不点击请求?
Sign In
用户将手动单击该按钮。 - 如何使用本机主机填写或传递凭据?本机主机将发送凭据,并且该凭据将传递给上述方法进行身份验证。
解决方案
推荐阅读
- batch-file - 批处理文件定时提醒
- mysql - LOAD DATA INFILE 返回 0 行受影响,MySQL 8
- entity-framework - Entity Framework 6:将复杂类型映射到多列
- postgresql - 为什么向索引添加排好序的列不能提高效率?
- google-sheets - 如果在谷歌表格中修改了值,则更改单元格颜色
- sql - 将日期转换为工作日,然后将其关联并求和
- html - 如何删除我的html页面两边的白边
- dialogflow-es - 处理“取消插槽填充对话框”
- azure - 如何将 Azure 分析服务模型推送到 azure devops git repo?
- vba - 搜索文本,在多个单元格中应用背景颜色