首页 > 解决方案 > 使用本机消息在 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

根据上述方法,它尝试使用给定的凭据进行身份验证。如果凭据正确,则将重定向到相应的页面。

问题

  1. 如何只填写凭据而不点击请求?Sign In用户将手动单击该按钮。
  2. 如何使用本机主机填写或传递凭据?本机主机将发送凭据,并且该凭据将传递给上述方法进行身份验证。

标签: javascriptasynchronousgoogle-chrome-extensionwebrequestchrome-native-messaging

解决方案


推荐阅读