Skip to content

Commit

Permalink
Ensure navigator.serial.getPorts errors don't break other plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Apr 15, 2021
1 parent 253798e commit 43e3778
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/serial_web_serial.js
Expand Up @@ -8,6 +8,9 @@
if (typeof navigator == "undefined") {
return {warning:"Not running in a browser"};
}
if (getPortsErrorMessage!==undefined) {
return {error:getPortsErrorMessage};
}
if (!navigator.serial) {
if (Espruino.Core.Utils.isChrome())
return {error:`Chrome currently requires <code>chrome://flags/#enable-experimental-web-platform-features</code> to be enabled.`};
Expand All @@ -26,6 +29,7 @@
}

var OK = true;
var getPortsErrorMessage = undefined;
var testedCompatibility = false;
/// List of previously paired devices that we could reconnect to without the chooser
var pairedDevices = [];
Expand All @@ -47,6 +51,9 @@
console.log("Serial> serial.getPorts exists - grab known devices");
navigator.serial.getPorts().then(devices=>{
pairedDevices = devices;
}, err=>{
getPortsErrorMessage = err.toString();
console.log("Serial> "+err.toString());
});
}
}
Expand Down

0 comments on commit 43e3778

Please sign in to comment.