npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@danidoble/webserial

v4.4.5

Published

WebSerial API wrapper

Downloads

209

Readme

Webserial API (Wrapper)

An easy way to connect to a serial port from a web page.

Ask DeepWiki npm version License: MIT

Opensource wrapper to simplify connect to serial devices over Webserial API

Also checkout the Webserial-core package if you want to integrate webserial into other projects.

Checkout the Docs for more information.

Install

Using npm

npm install @danidoble/webserial

Using pnpm

pnpm install @danidoble/webserial

Using bun

bun install @danidoble/webserial

Docs

If you want to use a custom or device or the other inside this package a good starter point would be Here

Example

In this example we'll use Arduino interface

<!-- index.html -->

<!doctype html>
<html lang="es">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Webserial</title>
    <script src="arduino.js" type="module"></script>
  </head>
  <body class="bg-neutral-950 text-white p-4 w-full">
    <div class="webserial w-full max-w-xl mx-auto grid grid-cols-1 gap-y-4">
      <div class="my-6"></div>
      <button id="connect" class="hidden px-4 py-3 bg-gray-800 rounded-lg">Connect to serial</button>

      <div id="need-permission" class="hidden p-4 bg-rose-900 rounded-lg">
        Woooah! It seems that you need to give permission to access the serial port. Please, click the button 'Connect
        to serial' to try again.
      </div>

      <div id="disconnected" class="hidden p-4 bg-neutral-900 w-full">
        The arduino is disconnected. Please, check the connection.
      </div>

      <div id="unsupported" class="hidden p-4 bg-orange-700 w-full absolute bottom-0 left-0">
        This browser does not support the WebSerial API. Please, use a compatible browser.
      </div>

      <div id="log" class="bg-neutral-800 p-4 rounded-lg">Log: <br /></div>
    </div>

    <script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,container-queries"></script>
  </body>
</html>
// arduino.js

import { Arduino } from '@danidoble/webserial';

const arduino = new Arduino();
arduino.on('serial:message', (data) => {
  console.log(data.detail);
});

arduino.on('serial:timeout', (data) => {
  console.log('serial:timeout', data.detail);
});

// arduino.on('serial:sent', data => {
//     console.log('serial:sent',data.detail);
// });

arduino.on('serial:error', (event) => {
  document.getElementById('log').innerText += event.detail.message + '\n\n';
});

// eslint-disable-next-line no-unused-vars
arduino.on('serial:disconnected', (event) => {
  document.getElementById('log').innerText += 'Disconnected\n\n';

  document.getElementById('disconnected').classList.remove('hidden');
  document.getElementById('connect').classList.remove('hidden');
});

// eslint-disable-next-line no-unused-vars
arduino.on('serial:connecting', (event) => {
  document.getElementById('log').innerText += 'Connecting\n\n';
});

// eslint-disable-next-line no-unused-vars
arduino.on('serial:connected', (event) => {
  document.getElementById('log').innerText += 'Connected\n\n';

  document.getElementById('disconnected').classList.add('hidden');
  document.getElementById('need-permission').classList.add('hidden');
  document.getElementById('connect').classList.add('hidden');
});

// eslint-disable-next-line no-unused-vars
arduino.on('serial:need-permission', (event) => {
  document.getElementById('disconnected').classList.remove('hidden');
  document.getElementById('need-permission').classList.remove('hidden');
  document.getElementById('connect').classList.remove('hidden');
});

// eslint-disable-next-line no-unused-vars
arduino.on('serial:soft-reload', (event) => {
  // reset your variables
});

// eslint-disable-next-line no-unused-vars
arduino.on('serial:unsupported', (event) => {
  document.getElementById('unsupported').classList.remove('hidden');
});

function tryConnect() {
  arduino
    .connect()
    .then(() => {})
    .catch(console.error);
}

document.addEventListener('DOMContentLoaded', () => {
  tryConnect();
  document.getElementById('connect').addEventListener('click', tryConnect);
});

// get device instance after
// import {Devices} from '@danidoble/webserial'
// const myDevice = Devices.getArduino(1);

// window.arduino = arduino;