学无先后,达者为师

网站首页 编程语言 正文

window.navigator.hid Cannot read properties of undefined

作者:鲁尼的小宝贝 更新时间: 2022-03-15 编程语言
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getDevices')
    at SoftKey3A.FindPort (SoftKey3A.js:278)
    at n.<anonymous> (index.js:105)
    at s (runtime.js:63)
    at Generator._invoke (runtime.js:293)
    at Generator.next (runtime.js:118)
    at a (asyncToGenerator.js:3)
    at s (asyncToGenerator.js:25)
    at asyncToGenerator.js:32
    at new Promise (<anonymous>)
    at n.<anonymous> (asyncToGenerator.js:21)

使用 navigator 读取识别 ukey,报出这个问题,在本地是可以的,但是在测试环境上就出问题了,报

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getDevices')

查询了好多地方,各种修改都报错。

突然详情,浏览器的api是否和ssl有关系,正式环境使用的是 https,使用没有问题,但是在测试环境使用的http,使用https访问就不会有这个问题了。

在这儿可以印证需要这个操作

https://developer.mozilla.org/en-US/docs/Web/API/HID

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

 

所以,非本地访问,得使用https访问。

原文链接:https://blog.csdn.net/poem_2010/article/details/122819624

栏目分类
最近更新