mbof / hxsync

Program Standard Horizon marine radios (HX870, HX890, HX891BT, and GX1400) from any computer using your browser
https://mbof.github.io/hx/
MIT License
4 stars 1 forks source link

Add a decent error message for browsers that lack the Web Serial API #36

Closed johannessen closed 6 months ago

johannessen commented 6 months ago

It’s easy to forget the serial connection doesn’t currently work in vanilla Firefox. You end up hammering the “Connect” button, wondering why nothing happens.

The app’s UI should inform the user of this limitation in a suitable way. For example, it could look like this:

var connectButton = document.querySelector(".controls > .desc + button");

// https://developer.chrome.com/docs/capabilities/serial#feature-detection
connectButton.addEventListener("click", function () {
  if ( "serial" in navigator ) {
    return;
  }
  alert(
    "This app depends upon the Web Serial API, which is unsupported in this web browser.\n\n"
    + "The Web Serial API is known to work in Chrome and Chromium-based browsers. Third-party extensions that add support to other browsers might exist."
  );
});
mbof commented 6 months ago

Oops, sorry about that. Good idea to add an error message!