1

I'm using WebSerial API to use thermal-printer in chrome browser, and want to access only 'COM1' port without requestPort.

Can I access to specific port and using that port?

nullromo
  • 2,165
  • 2
  • 18
  • 39
sunny
  • 31
  • 1

1 Answers1

1

For security purposes user consent is needed for the WebSerial API.

document.querySelector('button').addEventListener('click', async () => {
  // Prompt user to select any serial port.
  const port = await navigator.serial.requestPort();
});

After the first connection you could use this code to access previously consented ports by user

// Get all serial ports the user has previously granted the website access to.
const ports = await navigator.serial.getPorts();
Shankaja Aroshana
  • 551
  • 1
  • 3
  • 17