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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值