Navigator:credentials 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Navigator 接口的只读属性 credentials 返回与当前文档关联的 CredentialsContainer 对象,该对象暴露用于请求凭据的方法。CredentialsContainer 接口还会在发生感兴趣的事件时通知用户代理,例如成功登录或注销。此接口可用于特性检测。

一个 CredentialsContainer 对象。

示例

js
if ("credentials" in navigator) {
  navigator.credentials.get({ password: true }).then((creds) => {
    // 使用凭据执行操作
  });
} else {
  // 使用之前的方式处理登录
}

规范

Specification
Credential Management Level 1
# framework-credential-management

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
credentials

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support