【发布时间】:2018-11-17 21:37:30
【问题描述】:
以下示例 (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>
【问题讨论】:
-
如果您通过 HTTPS 端点访问会发生什么?
标签: amazon-web-services bluetooth web-bluetooth