{"id":42946294,"url":"https://github.com/goncalomb/sane-wasm","last_synced_at":"2026-01-30T20:36:30.800Z","repository":{"id":157712705,"uuid":"625278301","full_name":"goncalomb/sane-wasm","owner":"goncalomb","description":"A WebAssembly port of the SANE API.","archived":false,"fork":false,"pushed_at":"2025-07-01T17:25:22.000Z","size":195,"stargazers_count":80,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-17T22:40:06.960Z","etag":null,"topics":["libusb","sane","sane-backend","scanning","wasm","webassembly","webusb"],"latest_commit_sha":null,"homepage":"https://goncalomb.github.io/sane-wasm/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goncalomb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-LGPL.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-04-08T16:06:05.000Z","updated_at":"2025-08-07T11:53:35.000Z","dependencies_parsed_at":"2023-12-20T19:54:17.822Z","dependency_job_id":null,"html_url":"https://github.com/goncalomb/sane-wasm","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/goncalomb/sane-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goncalomb%2Fsane-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goncalomb%2Fsane-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goncalomb%2Fsane-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goncalomb%2Fsane-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goncalomb","download_url":"https://codeload.github.com/goncalomb/sane-wasm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goncalomb%2Fsane-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28918554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T20:25:28.696Z","status":"ssl_error","status_checked_at":"2026-01-30T20:25:13.426Z","response_time":66,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libusb","sane","sane-backend","scanning","wasm","webassembly","webusb"],"created_at":"2026-01-30T20:36:30.117Z","updated_at":"2026-01-30T20:36:30.784Z","avatar_url":"https://github.com/goncalomb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SANE WebAssembly (sane-wasm)\n\nA project to bring the [SANE API](http://www.sane-project.org/intro.html) to Node.js and the Web using WebAssembly.\n\nIt supports USB scanners on browser environments through the [WebUSB API](https://developer.mozilla.org/en-US/docs/Web/API/WebUSB_API) and on Node.js using [node-usb](https://github.com/node-usb/node-usb).\n\nThis works by compiling all SANE backends (and required dependencies) to WebAssembly using Emscripten. The other key piece is @RReverser's bridge from libusb to WebUSB ([article](https://web.dev/articles/porting-libusb-to-webusb)/[article](https://web.dev/articles/porting-gphoto2-to-the-web)/[code](https://github.com/libusb/libusb/pull/1057)/[code](https://github.com/libusb/libusb/pull/1339)) for direct USB access.\n\nRight now, it includes [all backends](http://www.sane-project.org/lists/sane-backends-cvs.html) that have support for at least one USB device ([genesys is not included due to issues](https://github.com/goncalomb/sane-wasm/issues/3)). No [external backends](http://www.sane-project.org/lists/sane-backends-external.html) are included at the moment.\n\n## WebScan\n\n**Check [webscan.goncalomb.com](https://webscan.goncalomb.com/) for a demo of sane-wasm.** This is a React application that uses sane-wasm for document/image scanning directly in the browser. It exposes all scanning options to the user for full control.\n\n## Usage\n\nThe pre-compiled WebAssembly package for sane-wasm is published on NPM:\n\nhttps://www.npmjs.com/package/sane-wasm?activeTab=code\n\n### For Web Environments (e.g. Webpack)\n\n```\nnpm install -D sane-wasm\n```\n\nThe main .js will not be bundled with your application. A loader ([lib/loader.js](https://github.com/goncalomb/sane-wasm/blob/master/lib/loader.js)) is provided to automatically load the .js/.wasm files from a CDN ([jsdelivr.com](https://www.jsdelivr.com/)). You can configure the loader to serve the files from your server if you want.\n\nSee [examples/webpack/](https://github.com/goncalomb/sane-wasm/tree/master/examples/webpack) for a working example.\n\n### For Node.js\n\n```\nnpm install sane-wasm usb\n```\n\nThe usb package ([node-usb](https://github.com/node-usb/node-usb)) is required to provide USB functionality.\n\nSee [examples/node/](https://github.com/goncalomb/sane-wasm/tree/master/examples/node) for a working example.\n\n### As Git Submodule (not recommended) / Custom Build\n\nAs an alternative, you can add sane-wasm as a [submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to your application and integrate `./build.sh` with your build process. This is not recommended as it relies on some magical/dubious code on `./build.sh` to make the build work.\n\nYou can also just build sane-wasm independently and use the build artifacts...\n\n```\n\u003cscript src=\"build/libsane.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    window.LibSANE().then(lib =\u003e {\n        // your code\n        console.log(lib.sane_init());\n    });\n\u003c/script\u003e\n```\n\n```\nconst { libsane } = require('./sane-wasm');\nlibsane().then(lib =\u003e {\n    console.log(lib.sane_init());\n});\n```\n\n```\nimport { libsane } from './sane-wasm';\nconst lib = await libsane();\nconsole.log(lib.sane_init());\n```\n\n## Building\n\n### SANE Only\n\nBuilding requires [emscripten](https://github.com/emscripten-core/emscripten) and all the required tools to build the dependencies.\n\nThe preferred way is just to use the pre-configured Docker image:\n\n    git clone --recurse-submodules https://github.com/goncalomb/sane-wasm.git\n    cd sane-wasm\n    ./build.sh --with-docker --clean\n\nStart the test server with:\n\n    ./build.sh --with-docker --no-build --emrun\n\nCheck the test page at: http://localhost:6931/libsane.html.\n\n#### build.sh\n\nThe `./build.sh` script has other options for debugging:\n\n```\nusage: build.sh [options]\n  --with-docker  run with docker (preferred)\n  --clean        clean 'deps' and 'build' directories\n  --no-build     don't actually build\n  --debug        enable debug flags\n  --emrun        run emrun development server\n  --shell        run debug shell (depends on --with-docker)\n```\n\n### Full Build (SANE + TypeScript)\n\nTo do a full build use `npm run build`.\n\n## API\n\nMost of the SANE API is exposed as-is. Check the [SANE Standard](https://sane-project.gitlab.io/standard/index.html).\n\nSome safeguards are in place to avoid API misuse and prevent memory leaks. It's important to understand the SANE API and follow the [Code Flow](https://sane-project.gitlab.io/standard/api.html#code-flow) to avoid issues.\n\n### Differences with the SANE API\n\nThe most important difference with the underlying SANE API is that **device handles are not exposed**. This means that `sane_open()` does not return a device handle. A single handle is managed by the internal code. This effectively means that **only one device can be accessed at a time**. This was a design decision made to simplify the API and prevent other issues.\n\n\u003e Personally, I believe that this is an acceptable change, especially for WebAssembly where it may be easier to lose track of opened resources and crash the application. The SANE API is also somewhat unforgiving and building more safeguards around it (especially with multiple handles) is not worth the effort. Ultimately I don't see a use that requires more than one device open at a time. -goncalomb\n\n### Documentation\n\nCheck API documentation at: [goncalomb.github.io/sane-wasm/modules.html](https://goncalomb.github.io/sane-wasm/modules.html).\n\n## License\n\nBecause of the weird state of SANE's licensing (GPL + linking exception, on some backends), see [backends/LICENSE](https://gitlab.com/sane-project/backends/-/blob/master/LICENSE). I'm releasing this project with dual licensing [GNU GPLv2](https://github.com/goncalomb/sane-wasm/blob/master/LICENSE.txt) + [GNU LGPLv2.1](https://github.com/goncalomb/sane-wasm/blob/master/LICENSE-LGPL.txt). IANAL, you choose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoncalomb%2Fsane-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoncalomb%2Fsane-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoncalomb%2Fsane-wasm/lists"}