以下示例 (1) 列出了在 Chrome 版本 70 中作为文件打开时可用的蓝牙设备。
将完全相同的示例上传到 Amazon Ligtsail 实例时,我收到以下错误消息:
Uncaught TypeError: Cannot read property 'requestDevice' of undefined
at connect ((index):9)
at HTMLButtonElement.onclick ((index):4)
谁能向我解释可能是什么问题?由于这是 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>