Hacker News new | past | comments | ask | show | jobs | submit login
WebAssembly+WebUSB port of the SANE scanner library (github.com/goncalomb)
101 points by RReverser on April 29, 2023 | hide | past | favorite | 26 comments



IMO one of the biggest opportunities for WASM is printer and scanner drivers. These things have historically been distributed as native code, so the usability of the hardware on various OSes and architectures is spotty[0]. WASM is close enough to a native binary (fast, not source[1]) to be accepted by hardware vendors, but is inherently architecture-independent and in principle could be built to an OS-indendent API. Imagine sharing the exact same drivers for tens of thousands of devices across Windows, Mac, Linux, and every other OS that might exist in the future!

The same applies to webcams, screensavers (with WebGL/WebGPU), audio processing plugins, and any other software that doesn't come bundled into the OS and doesn't have a UI as such.

The utility of WebASM for non-Web use cases is incredible.

[0] My scanner is by Epson, who have good Linux support, but the driver was built against an ancient GNU libc that's no longer distributed by Debian/Ubuntu. And it's amd64, so I can't use a RaspberryPi as a scan server.

[1] I prefer open source when available, but hardware vendors often have cultural or contractual blocks against open-sourcing their drivers.


So you feel that e.g. Epson, who could not be bothered to rebuild their existing C-ish driver against a newer version of libc, will instead port it to WASM because ... when they already have working drivers for macOS and Windows that they currently maintain ....

I'm lost.


If the standard for Linux scanner drivers was WASM, then companies who publish Linux drivers (such as Epson) would receive perfect forward compatibility for free.

If WASM driver support were to be included in Windows and/or macOS, similar to how macOS and Linux share CUPS, then Linux support would be more widespread because the vendor's driver could be reused as-is.

I think the thought process behind "supporting one unified platform-independent bytecode would be easier than compiling a .so that works with all GNU libc versions" is straightforward and self-evident. Do you disagree?


> I think the thought process behind "supporting one unified platform-independent bytecode would be easier than compiling a .so that works with all GNU libc versions" is straightforward and self-evident. Do you disagree?

1. it doesn't really matter what I think

2. Compiling a .so that works with all glibc versions is almost certainly an order of magnitude easier than providing a unified wasm implementation that works on (at least) 3 platforms.


If only there were some kind of language that could compile to a code that could be run on any operating system that could be used for this sort of thing. Oh wait, it's Java and it's been around for 25 years. But quite restricted in it's interaction with the OS, for good reason. As is WASM, for good reason as well. If printer drivers in Java didn't become a thing, I doubt that WASM printer drivers will.

Though I can't really understand why a printer driver needs such low level OS access so as to become a security risk as they sometimes are - aren't they basically a program that converts one image format to another, then flings that down a USB or network port?


WASM is not a language though, the equivalent here would be a JVM, but that enforces all sorts of Java specific constraints that you do not want in a driver.

The short answer to your question is: No.


Yeah, I get that WASM is like JVM (or even more accurately, java bytecode), but doesn't WASM have as many constraints on it?

Can you elaborate on your answer? Linux printer drivers seem to be entirely in userspace, so why do Windows drivers cause so much grief?


The problem with printers specifically is that drivers are much more than just a hardware communication layer. Drivers on Windows create the "printing options" UI, which is where most of the interesting functionality is accessed from. Such a common driver interface would have to define a cross-platform UI layer or at least a very advanced configuration API that the print service would render.


I was just asking about this in a thread about a driver for an old webcam here yesterday! [0]

Absolutely agreed, it really seems like a fascinating possibility.

What’s your take on how WASM drivers (meant to run in a web browser) could integrate at the OS level? For instance, if you wanted all installed desktop softwares to be able to print via the WASM printer driver?

[0] https://news.ycombinator.com/item?id=35745652


I don't see any reason why wasm can't just become another native format.

wasm spec is fully defined and public, and we even already have source for browsers.

What prevents developing a wrapper or shim that runs any wasm as if it were any other native executable?

You might be legally prevented from redistributing the wasm, so maybe you can't bundle it right into a .deb or.rpm, but it's trivial in that case to just download on the fly if not exist and re-use after that. You may want it to check for updates all the time anyway.


It's typically called a VM. Go up and read about Java, which was fundamentally premised on precisely the same idea, and then see if you can come with some clear reasons why wasm should/will be more successful.


I don't think java has much equivalence or bearing here.


It is a VM like wasm. It runs on every platform. It offers the seduction of "write once, run anywhere" (literally, in the Java marketing, and now increasingly, in discussions about wasm. The more wasm expands its capabilities due to browser extensions the more and more it looks like Java as a platform.


neither java code nor binaries are very portable, despite the original marketing. wasm is essentially a binary format. You can certainly make a non-portable wasm just the same way you can make a non-portable elf binary. But you don't have to. You can make a wasm that is even more portable than any elf binary since it's independent of any platform. java byte code may have been theoretically able to do the same, but the jvm ended up being too varied and there is no universal jvm environment the way there is a universal wasm environment. Browser extensions don't remove or modify the base, only add.

java isn't relevant, not because it couldn't be in theory, but because in reality, it's just not. Browsers never baked it in, it never became an open standard, etc, it's essentially no better than every other interpreted or compiled language. We could have a universal standard that's essentially bash, but we don't. We have bash, but it will never be a universal format the way wasm already is. Being baked into everyone's browser makes all the difference. When you want to publish a picture, tiff is a very versatile container and is better than most other formats, but the format you will actually use will be png or jpg etc, because even though many tiff viewers are available, they aren't built in to all browsers. It doesn't matter that tiff already existed and could do the same job. java is tiff.


> What prevents developing a wrapper or shim that runs any wasm as if it were any other native executable?

That definitely exists and is used on server-side - Wasmtime, Wasmer and others.


Application software would still go through the OS native printing APIs. Office or Chrome don't directly interact with the vendor's driver.

As for browser API compatibility, I don't see much point to it since they're mostly designed with the assumption of a JS host. Ideally a WASM driver would export low-level functions to translate from (for example) PostScript to USB packets. Then the underlying native driver (Linux kernel module, Windows dll, etc) runs the WASM and handles all the IO, calling exported WASM functions as needed.


Browser ports can't integrate at OS level, they're intentionally separated today, but given that e.g. Node.js has WebUSB support (https://github.com/node-usb/node-usb), I guess you could make a layer that exposes such Wasm drivers as native to the OS. Could be a fun experiment.


Many years ago friend gave me broken SCSI scanner. It always said "paper jammed". I thought I just short or remove the paper sensor but it wasn't simple kind of sensor, there were two and from the delay it decided whether the paper was jammed or not.

So I downloaded the source code of SANE, find the offending error message, commented it out and scanner worked without issue.


I had one of these stupid AMD graphics cards (I think from the Evergreen generation) where the GPU/memory clocks would be locked in at the highest frequency whenever you had a second monitor plugged in. Apparently some sort of graphical glitches would be possible otherwise. In their infinite wisdom, AMD decided it was worth an extra 20W of baseline power consumption to avoid these glitches. (I am told they still do this as of today).

So I went the radeon kernel driver, and simply commented out that part. Never had a single glitch for the entire lifetime of the card, but oh god I did enjoy the silent fan-free operation.

And people wonder why I'm a staunch fanatic of free software.



Hi. I'm the port author. I'm not really active here on HN, but thanks for all the clicks.


This is interesting, however to pour a bit of water on the opportunities here:

- CUPS has existed for over 20 years

- Java has existed for over 25 years

However, I still not use CUPS or similar systems on Windows. And Java-based (or other VM-based) printer drivers have never been a thing AFAIK, on any platform.

There are however platform independent device support at a lower level, e.g. OpenFirmware and EFI. This is usually not leveraged post-boot.


I just purchased a Chromebook, and it won't detect the scanner of my HP multifunction. Is this software my salvation?


This is the list of possible supported devices right now (USB only):

http://www.sane-project.org/sane-backends.html

But HP is a special case, they provide their own backend (hpaio, open-source) for SANE that is not integrated into sane-wasm ATM.

http://www.sane-project.org/lists/sane-backends-external.htm...

If your device is on this list, it's NOT supported right now! But I do want to add hpaio soon, I also have access to an OfficeJet to test.


Chromebook is probably the perfect target for those kinds of ports. Definitely worth giving a try, hopefully SANE supports it.


Now the IPP-Anywhere / driverless IPP, AirPrint, and driverless scanning is a thing, I think this is sadly too late.

Go to the Drivers page on Brother's website, and for any recent macOS version, the answer is, "just use AirPrint".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: