skip to Main Content

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://phpout.com/wp-content/uploads/2023/10/NerEz.png)

[script execution with chromium] (https://phpout.com/wp-content/uploads/2023/10/XehdH.png)

[script opened in debug console with chromium] https://phpout.com/wp-content/uploads/2023/10/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

2

Answers


  1. Chosen as BEST ANSWER

    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,


  2. I remember having a situation like that few years ago, I’ve just looked at some old notes and it was something to do with enabling usb connection with Chromium?

    sudo snap connect chromium:raw-usb
    

    I don’t know if that’s of any help or if it was something specific to my system at the time?

    Lately I tend to stick with Node.js now for serial communication with my ESPs but it is a bit more involved process and if you can do it through the browser it is a great shortcut.

    Good luck

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search