最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Navigator.bluetooth does not exist - Stack Overflow

programmeradmin0浏览0评论

I have a simple page hosted on locally that uses the bluetooth webAPI. When opening the page through localhost the script works as intended but when I connect to the server through using my IP on my puter or another it doesn't work, The error I got was: Uncaught TypeError: Cannot read properties of undefined (reading 'requestDevice'). I tried logging the Navigator object and saw that it had noticeably less properties on the remove connection than on the localhost, one of the missing properties was Bluetooth. Why does the Navigator object has less properties on the remote connection? and is it possible to fix it?

How it looks like on localhost:

How it looks like on remote connection:

I have a simple page hosted on locally that uses the bluetooth webAPI. When opening the page through localhost the script works as intended but when I connect to the server through using my IP on my puter or another it doesn't work, The error I got was: Uncaught TypeError: Cannot read properties of undefined (reading 'requestDevice'). I tried logging the Navigator object and saw that it had noticeably less properties on the remove connection than on the localhost, one of the missing properties was Bluetooth. Why does the Navigator object has less properties on the remote connection? and is it possible to fix it?

How it looks like on localhost:

How it looks like on remote connection:

Share Improve this question asked Aug 14, 2022 at 9:04 Guy LeviGuy Levi 455 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

According to https://web.dev/bluetooth/#https-only. Web Bluetooth is only available in secure browsing contexts. It means you either have to serve your webpage over https:// or localhost such as http://127.0.0.1 or http://localhost.

So it means you might want to always use https, and http://localhost is an exception for local development convenience.

发布评论

评论列表(0)

  1. 暂无评论