Hardware Web API feature detection

Updated on 23 September 2022
tool Chrome web browser
features hardware Web geolocation BLE WebUSB
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Code

Download code View demo web-hw-feature-detection-demo.html
<p>Please open the browser dev console to view whether geolocation, web ble and web usb are available in this browser.</p>

<script>
  if (navigator.geolocation) {
    console.log('%c Geolocation API is available in this browser!', 'color: #006400')
  } else {
    console.log('%c Geolocation API is not available in this browser.', 'color: #8b0000')
  }

  if (navigator.bluetooth) {
    console.log('%c Web Bluetooth API is available in this browser!', 'color: #006400')
  } else {
    console.log('%c Web Bluetooth API is not available in this browser.', 'color: #8b0000')
  }

  if (navigator.usb) {
    console.log('%c Web USB API is available in this browser!', 'color: #006400')
  } else {
    console.log('%c Web USB API is not available in this browser.', 'color: #8b0000')
  }
</script>

Description

This example contains feature detection code in JavaScript. Load the HTML file file via a server on different browsers to see whether geolocation, Web BLE and Web USB are supported.

Chrome

![]https://hutscape.com/assets/images/tutorials/web-hw-feature-detection-chrome.png)

Safari

![]https://hutscape.com/assets/images/tutorials/web-hw-feature-detection-safari.png)

References