问题
Are PWA functionality (service-worker) can help or there no way to do that?
回答1:
This document contains a sample program that prints easily using the socket interface in C language.
UB-E04 Technical Reference Guide
It seems that the equivalent can be implemented using JavaScript WebSocket.
This article is available in both Japanese and English, and both provide examples of using WebSocket easily from vanilla JavaScript.
5分で動かせるwebsocketのサンプル3つ / WebSocket Tutorials
Introducing WebSockets: Bringing Sockets to the Web
The following is a sample program in Linux C language described in the document.
Sending to a printer can be done with such a simple program.
The data to be sent must be created in the format described in the ESC/POS command reference.
/* TCP9100 programming sample for LINUX * HOW TO BUILD * cc ltcp.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <netdb.h> int main(int argc, char* argv[]) { int sock; struct sockaddr_in addr; if (argc != 2) { printf("usage: ltcp <ip address>\n"); exit(1); } /* create socket */ sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { perror("socket()"); exit(1); } /* initialize the parameter */ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(9100); addr.sin_addr.s_addr = inet_addr(argv[1]); /* connect */ if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) { perror("connect()"); } printf("connected\n"); /* send data */ send(sock, "EPSON UB-E04\n", 13, 0); /* close socket */ close(sock); return 0; }
来源:https://stackoverflow.com/questions/59517689/is-there-any-way-to-print-from-google-chrome-to-thermal-printer-escpos-in-loca