检查浏览器的 U2F 功能

Check browser for U2F capability

本文关键字:功能 U2F 浏览器 检查      更新时间:2023-09-26

有没有办法检查浏览器是否支持U2F?

我知道现在,Chrome是唯一正式使用U2F的浏览器,

但是有Firefox的插件,也可能有定制的浏览器可能已经获得了U2F。

我不想像谷歌那样放弃这样的浏览器,因为插件用户将无法使用它。

我看到GitHub似乎有

办法看到它(因为它区分了有插件和没有插件的Firefox),但我不知道该怎么做。

使用库 caniuse-support,它使用来自服务 caniuse.com (https://caniuse.com/#feat=u2f) 的信息并使用库 Bowser(浏览器检测器):

const {
  getSupport,
  currentBrowser,
} = CaniuseSupport;
const test1 = getSupport("u2f"); // current browser
console.log(
  "Get feature support of U2F current browser (" +
    currentBrowser.id +
    " " +
    currentBrowser.version +
    "):",
  test1.level
);

代码笔沙盒

现在是

2019年,实际上整个U2F的东西都有一些有趣的改进。

U2F浏览器API基本上已经被WebAuthn取代,虽然可以肯定的是,这正在抛弃一些较旧的浏览器,但实际上没有任何相关的旧浏览器实际上支持U2F API,无论如何,U2F API仍然被广泛使用,Chrome及其分支基本上是唯一本地支持U2F的浏览器开箱即用。

使用新的 webauthn,您可以根据我在示例文档中使用的库来实际检查函数:

if (!navigator.credentials || !navigator.credentials.create) { 
  //try navigator.credentials.get for login instead of create
  //tell the user
}