window.navigator.hid Cannot read properties of undefined

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访问。


版权声明:本文为poem_2010原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。