How to read COM ports? navigator.serial.getPorts returns empty list

Solution 1:

You need to request the user's permission to read the Serial's ports by first calling navigator.serial.requestPort():

onclick = async () => {

  await navigator.serial.requestPort();
  console.log( await navigator.serial.getPorts() );

};

Live example