Search code examples
google-chromeubuntuarduinoserial-portchromium

Could not list serial ports with web serial API in chromium 118.0.5993.88 (snap) on ubuntu 20.04


I want to establish a serial connection with a esp32 (connected via USB to my PC) and a test website on chromium (version 118.0.5993.88, Ubuntu 20.04) but the list of serial connections is empty on chromium (on google chrome the list shows every serial ports)

Here is the test html-script that I used:

<!DOCTYPE html>
<html>
<head>
  <title>Serial Ports List</title>
</head>
<body>

<h1>Serial Ports Test</h1>

<!-- Button to list available serial ports -->
<button id="listPortsButton">List Serial Ports</button>

<script>
  // Function to list available serial ports
  async function listSerialPorts() {
    try {
      // Request access to serial ports
      const availablePorts = await navigator.serial.getPorts();

      // Log each port
      availablePorts.forEach(port => {
        console.log('Port:', port);
      });
    } catch (error) {
      console.error('There was an error listing serial ports:', error);
    }
  }

  // Add click event listener to button
  document.querySelector("#listPortsButton").addEventListener("click", 
async () => {
    try {
      // Request a port from the user
      const port = await navigator.serial.requestPort();
      console.log('User-selected port:', port);

      // Now list all available ports (including the selected one)
      listSerialPorts();
    } catch (err) {
      console.error('There was an error selecting a port:', err);
    }
  });
</script>

</body>
</html>

[script execution with google chrome] https://i.sstatic.net/NerEz.png)

[script execution with chromium] (https://i.sstatic.net/XehdH.png)

[script opened in debug console with chromium] https://i.sstatic.net/F3w3N.png)

System infos:

1. 2.

I already tried the script with google chrome (as shown above) and there it works and I also reinstalled chromium to check if there are problems with my chromium installation. I want to get the script work like it works in google chrome and need help.

I also checked the serial connection in arduino and the serial port shows in the list, I can connect to it and open the serial monitor without problems. The user is also in the right group to have access to the serial ports.

Edit:

  • I tried to use the command: sudo snap connect chromium:raw-usb - still doesn't work

  • The user is also in the group dialout for the right permissions


Solution

  • I fixed this issue. The problem came with snap. I installed chromium with snap and it seems that the snap app was restricted so I had to add those two lines to the chromium snap profile located at: /var/lib/snapd/apparmor/profile/snap.chromium.chromium

    @{PROC}/tty/drivers r,

    /run/udev/data/** r,