{"id":18843721,"url":"https://github.com/nielsleenheer/webusbreceiptprinter","last_synced_at":"2025-10-05T21:47:41.365Z","repository":{"id":156792042,"uuid":"628953727","full_name":"NielsLeenheer/WebUSBReceiptPrinter","owner":"NielsLeenheer","description":"Print to a USB connected receipt printer using WebUSB","archived":false,"fork":false,"pushed_at":"2024-10-04T16:49:34.000Z","size":76,"stargazers_count":38,"open_issues_count":6,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-21T02:56:57.637Z","etag":null,"topics":["fugu","printer","receipt","webusb"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NielsLeenheer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-17T10:19:13.000Z","updated_at":"2025-08-31T00:25:40.000Z","dependencies_parsed_at":"2024-09-18T13:18:18.476Z","dependency_job_id":"68a1ae40-f25c-42be-8c1b-9ccc30bc4a86","html_url":"https://github.com/NielsLeenheer/WebUSBReceiptPrinter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"rollup/rollup-starter-lib","purl":"pkg:github/NielsLeenheer/WebUSBReceiptPrinter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebUSBReceiptPrinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebUSBReceiptPrinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebUSBReceiptPrinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebUSBReceiptPrinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NielsLeenheer","download_url":"https://codeload.github.com/NielsLeenheer/WebUSBReceiptPrinter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebUSBReceiptPrinter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278526244,"owners_count":26001325,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["fugu","printer","receipt","webusb"],"created_at":"2024-11-08T02:58:37.999Z","updated_at":"2025-10-05T21:47:41.330Z","avatar_url":"https://github.com/NielsLeenheer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebUSBReceiptPrinter\n\nThis is an library that allows you to print to a USB connected receipt printer using WebUSB.\n\n\u003cbr\u003e\n\n[![npm](https://img.shields.io/npm/v/@point-of-sale/webusb-receipt-printer)](https://www.npmjs.com/@point-of-sale/webusb-receipt-printer)\n![GitHub License](https://img.shields.io/github/license/NielsLeenheer/WebUSBReceiptPrinter)\n\n\n\u003e This library is part of [@point-of-sale](https://point-of-sale.dev), a collection of libraries for interfacing browsers and Node with Point of Sale devices such as receipt printers, barcode scanners and customer facing displays.\n\n\u003cbr\u003e\n\n## What does this library do?\n\nIn order to print a receipt on a receipt printer you need to build the receipt and encode it as in the ESC/POS or StarPRNT language. You can use the [`ReceiptPrinterEncoder`](https://github.com/NielsLeenheer/ReceiptPrinterEncoder) library for this. You end up with an array of raw bytes that needs to be send to the printer. One way to do that is using a direct USB connection using WebUSB.\n\n### Unfortunately this does not work on Windows...\n\nOn most platforms you can directly talk to USB connected receipt printers using WebUSB. The main exception to this is on Windows where the printer driver exclusively claims the printer. On that platform the alternative way to print on receipt printers would be to use allow to driver to create a virtual serial port for the printer. Usually this is used for compatibility with old applications, but it also means you can use the `WebSerialReceiptPrinter` library instead.\n\nUnfortunately...\n\nThere seems to be an incompatibility between the WebSerial implementation and the virtual serial port that the Star printer driver creates. That means this workaround does not work for Star printers.\n\n\u003cbr\u003e\n\n## How to use it?\n\nLoad the `webusb-receipt-printer.umd.js` file from the `dist` directory in the browser and instantiate a `WebUSBReceiptPrinter` object. \n\n```html\n\u003cscript src='webusb-receipt-printer.umd.js'\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n\n    const receiptPrinter = new WebUSBReceiptPrinter();\n\n\u003c/script\u003e\n```\n\nOr import the `webusb-receipt-printer.esm.js` module:\n\n```js\nimport WebUSBReceiptPrinter from 'webusb-receipt-printer.esm.js';\n\nconst receiptPrinter = new WebUSBReceiptPrinter();\n```\n\n\u003cbr\u003e\n\n## Connect to a receipt printer\n\nThe first time you have to manually connect to the receipt printer by calling the `connect()` function. This function must be called as the result of an user action, for example clicking a button. You cannot call this function on page load.\n\n```js\nfunction handleConnectButtonClick() {\n    receiptPrinter.connect();\n}\n```\n\nSubsequent times you can simply call the `reconnect()` function. You have to provide an object with the serial number, vendor id and product id of the previously connected receipt printer in order to find the correct printer and connect to it again. You can get this data by listening to the `connected` event and store it for later use. It is recommended to call this button on page load to prevent having to manually connect to a previously connected device.\n\n```js\nreceiptPrinter.reconnect(lastUsedDevice);\n```\n\nIf there are no receipt printers connected that have been previously connected, or the serial number does not match up, this function will do nothing.\n\nTo find out when a receipt printer is connected you can listen for the `connected` event using the `addEventListener()` function.\n\n```js\nreceiptPrinter.addEventListener('connected', device =\u003e {\n    console.log(`Connected to ${device.manufacturerName} ${device.productName} (#${device.serialNumber})`);\n\n    printerLanguage = device.language;\n    printerCodepageMapping = device.codepageMapping;\n\n    /* Store device for reconnecting */\n    lastUsedDevice = device;\n});\n```\n\nThe callback of the `connected` event is passed an object with the following properties:\n\n-   `type`\u003cbr\u003e\n    Type of the connection that is used, in this case it is always `usb`.\n-   `vendorId`\u003cbr\u003e\n    The USB vendor ID.\n-   `productId`\u003cbr\u003e\n    The USB product ID.\n-   `manufacturerName`\u003cbr\u003e\n    The name of the manufacturer of the printer.\n-   `productName`\u003cbr\u003e\n    The name of the receipt printer.\n-   `serialNumber`\u003cbr\u003e\n    The serial number of the receipt printer. To be used to reconnect to the printer at a later time.\n-   `language`\u003cbr\u003e\n    Language of the printer, which can be either `esc-pos` or `star-prnt`. This can be used as an option for `ReceiptPrinterEncoder` to encode in the correct language for the printer.\n-   `codepageMapping`\u003cbr\u003e\n    Code page mapping of the printer, which can be used as an option for `ReceiptPrinterEncoder` to map non-ascii characters to the correct codepage supported by the printer. \n\n\u003cbr\u003e\n\n## Commands\n\nOnce connected you can use the following command to print receipts.\n\n### Printing receipts\n\nWhen you want to print a receipt, you can call the `print()` function with an array, or a typed array with bytes. The data must be properly encoded for the printer. \n\nFor example:\n\n```js\n/* Encode the receipt */\n\nlet encoder = new ReceiptPrinterEncoder({\n    language:  printerLanguage,\n    codepageMapping: printerCodepageMapping\n});\n\nlet data = encoder\n    .initialize()\n    .text('The quick brown fox jumps over the lazy dog')\n    .newline()\n    .qrcode('https://nielsleenheer.com')\n    .encode();\n\n/* Print the receipt */\n\nreceiptPrinter.print(data);\n```\n\n\u003cbr\u003e\n\n-----\n\n\u003cbr\u003e\n\nThis library has been created by Niels Leenheer under the [MIT license](LICENSE). Feel free to use it in your products. The  development of this library is sponsored by Salonhub.\n\n\u003ca href=\"https://salohub.nl\"\u003e\u003cimg src=\"https://salonhub.nl/assets/images/salonhub.svg\" width=140\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnielsleenheer%2Fwebusbreceiptprinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnielsleenheer%2Fwebusbreceiptprinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnielsleenheer%2Fwebusbreceiptprinter/lists"}