{"id":18843723,"url":"https://github.com/nielsleenheer/webbluetoothreceiptprinter","last_synced_at":"2025-10-29T14:02:14.996Z","repository":{"id":233375868,"uuid":"630350141","full_name":"NielsLeenheer/WebBluetoothReceiptPrinter","owner":"NielsLeenheer","description":"Print to a Bluetooth connected receipt printer using WebBluetooth","archived":false,"fork":false,"pushed_at":"2024-10-04T16:49:06.000Z","size":69,"stargazers_count":50,"open_issues_count":5,"forks_count":9,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-22T05:43:56.273Z","etag":null,"topics":["fugu","printer","receipt","webbluetooth"],"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-20T07:39:24.000Z","updated_at":"2025-08-18T14:14:25.000Z","dependencies_parsed_at":"2024-04-16T01:01:30.924Z","dependency_job_id":"3cc0f654-7c22-4cb6-a6b6-aeaa48341910","html_url":"https://github.com/NielsLeenheer/WebBluetoothReceiptPrinter","commit_stats":null,"previous_names":["nielsleenheer/webbluetoothreceiptprinter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NielsLeenheer/WebBluetoothReceiptPrinter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebBluetoothReceiptPrinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebBluetoothReceiptPrinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebBluetoothReceiptPrinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebBluetoothReceiptPrinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NielsLeenheer","download_url":"https://codeload.github.com/NielsLeenheer/WebBluetoothReceiptPrinter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NielsLeenheer%2FWebBluetoothReceiptPrinter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273122280,"owners_count":25049552,"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-09-01T02:00:09.058Z","response_time":120,"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","webbluetooth"],"created_at":"2024-11-08T02:58:38.539Z","updated_at":"2025-10-29T14:02:14.990Z","avatar_url":"https://github.com/NielsLeenheer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebBluetoothReceiptPrinter\n\nThis is an library that allows you to print to a Bluetooth connected receipt printer using WebBluetooth.\n\n\u003cbr\u003e\n\n[![npm](https://img.shields.io/npm/v/@point-of-sale/webbluetooth-receipt-printer)](https://www.npmjs.com/@point-of-sale/webbluetooth-receipt-printer)\n![GitHub License](https://img.shields.io/github/license/NielsLeenheer/WebBluetoothReceiptPrinter)\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 this library and WebBluetooth.\n\n\u003cbr\u003e\n\n## How to use it?\n\nLoad the `webbluetooth-receipt-printer.umd.js` file from the `dist` directory in the browser and instantiate a `WebBluetoothReceiptPrinter` object. \n\n```html\n\u003cscript src='webbluetooth-receipt-printer.umd.js'\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n\n    const receiptPrinter = new WebBluetoothReceiptPrinter();\n\n\u003c/script\u003e\n```\n\nOr import the `webbluetooth-receipt-printer.esm.js` module:\n\n```js\nimport WebHIDBarcodeScanner from 'webbluetooth-receipt-printer.esm.js';\n\nconst receiptPrinter = new WebBluetoothReceiptPrinter();\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\nIn the future, there is a way to reconnect to already connected printers. This functionality is still behind a flag in currently shipping browsers. To do it you can simply call the `reconnect()` function. You have to provide an object with the 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 id 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.name} (#${device.id})`);\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 `bluetooth`.\n-   `name`\u003cbr\u003e\n    The name of the receipt printer.\n-   `id`\u003cbr\u003e\n    A unique id for 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%2Fwebbluetoothreceiptprinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnielsleenheer%2Fwebbluetoothreceiptprinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnielsleenheer%2Fwebbluetoothreceiptprinter/lists"}