Amazon Lightsail 上未定义蓝牙 requestDevice()

Att*_*que 2 bluetooth amazon-web-services web-bluetooth

以下示例 (1) 列出了在 Chrome 版本 70 中作为文件打开时可用的蓝牙设备。

将相同的示例上传到 Amazon Ligtsail 实例时,我收到以下错误消息:

Uncaught TypeError: Cannot read property 'requestDevice' of undefined
at connect ((index):9)
at HTMLButtonElement.onclick ((index):4)
Run Code Online (Sandbox Code Playgroud)

谁能向我解释一下问题可能是什么?既然这是 JavaScript,它应该在浏览器中执行并且与任何服务器设置无关?

。

(1) 在 Amazon Lightsail 上生成错误的示例代码

<html>
<body>
<button onclick="connect();">Click here</button>
<script>
function connect() {
    console.log('Getting Bluetooth Device...');
    navigator.bluetooth.requestDevice(
    {
        acceptAllDevices : true
    })
    .then(device => {
        console.log('Got device');
    })
     .catch(error => {
        console.log(error);
    });
 }
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Att*_*que 6

正如 @kdgregory 所建议的,navigator.bluetooth仅限HTTPS:

由于这个实验性 API 是添加到 Web 中的一项强大的新功能,因此 Google Chrome 的目标是使其仅可用于安全上下文。这意味着您需要在构建时牢记 TLS。

我添加了一个GitHub 页面并且它可以工作。

在此输入图像描述