为什么我得到“Uncaught TypeError:navigator.bluetooth.getAvailability不是函数”
问题描述:
以下代码在Chrome版本59.0.3071.134(官方版本)(64位)上执行的chromebook正在生成“Uncaught TypeError: navigator.bluetooth.getAvailability不是一个函数“。任何想法为什么?为什么我得到“Uncaught TypeError:navigator.bluetooth.getAvailability不是函数”
bluetoothle.checkBluetoothAvailable = function() {
console.log("checkBluetoothAvailable");
navigator.bluetooth.getAvailability().then(isAvailable => {
document.getElementById('btn_discover').hidden = !isAvailable;
if (!isAvailable) {
document.getElementById('message').innerHTML = 'Bluetooth is not available';
}
});
navigator.bluetooth.addEventListener('availabilitychanged', e => {
document.getElementById('btn_discover').hidden = !e.value;
if (!e.value) {
document.getElementById('message').innerHTML = 'Bluetooth is not available';
} else {
document.getElementById('message').innerHTML = 'Bluetooth is available';
}
});
}
答
getAvailability未实现。这是明确的,所以尝试它并且期望它能够工作是有意义的。
https://github.com/WebBluetoothCG/web-bluetooth/blob/gh-pages/implementation-status.md列出了更详细实施的内容。
而且,在规范中,您会发现某些部分的背景(如getAvailability)包含“此部分不稳定”。和背景文字“不稳定”。
好吧,明白了。谢谢 :-) – martianw