mbof / hxsync

MIT License
4 stars 0 forks source link

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

Closed johannessen closed 4 months ago

johannessen commented 4 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 4 months ago

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