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