CORS policy problem with Zebra Printers

// Expert user has replied.
B Brian Wilson 1 year 5 months ago
860 4 0

I suppose this isn't directly browser print related, but I am attempting to either use BrowserPrint which I can't get working at all or simply a post request to http://{printerIP}/pstprnt to print qr codes on a Zebra ZT230. 

 

The post request method is working successfully in development, but the moment I deploy my application and either attempt to hit the printer with a post request at HTTP or HTTPS, I am blocked by CORS policy, and I am reading that this is because the printer does not send back a header with Access-Control-Allow-Origin: "*".

 

It's a bit frustrating that there is such a lack of documentation and nothing but outdated SDK's surrounding these printers. Is there anyone who has successfully deployed an app or knows how to work past this CORS error? If this can work, I wouldn't touch browser print with a 10 foot pole. I just need to be able to print a label on demand from my web app, and like I said, it's working in development but not in deployment.

 

I am using a Next.js (React) app with an ASP.NET Cor Web API backend. I am working behind a pretty strict corporate proxy as well, and the client-side request I showed above to the pstprnt endpoint is the only thing that seemed to even have a chance of working, and then the CORS issue popped up.

 

This issue is mentioned here:

 

https://supportcommunity.zebra.com/s/question/0D56S00009DYjcjSAD/has-browserprint-stopped-working-in-chrome-due-to-cors-issue?language=en_US

 

Please Register or Login to post a reply

4 Replies

S Steven Si

There is a mini webservice built into the firmware of Zebra printers that accepts the http://{printerIP}/pstprnt POST request for printing. This mini webservice has not been updated for awhile and does not handle more modern security improvements in browsers. That's why the CORS errors pop up, though the print will happen correctly. The pstprint is still an option for printing from browsers, if the web application can accept or ignore this particular CORS error.

For the Browser Print, it is a better option than the pstprnt. The Browser Print supports Windows, MacOS and Android, and supports the network, USB or Bluetooth (for Android) connected printers. Besides, the Browser Print gets updated on a regular basis. The Browser Print requires a local client app runs in background that bridges the communication between the web app running in the browser and the printers connected via network, USB or Bluetooth (for Android).

B Brian Wilson

Hi there and thank you for your response.

I have to say the installation of an app is not ideal for any app that is intended to scale widely, though it’s not egregious either given that getting an installation on any computers that need the browser print bridge app is not a huge deal.

Do you know if the Asp.Net SDK “Zebra.Printing.SDK” (or whatever it is, sorry I’m not at the computer right now) has any issues with this? If I were to utilize it in an ASP.NET core web api from server side rather than client side, maybe that would bypass any issues?

I will have to test it tomorrow to find out I suppose..

S Steven Si

The Zebra.Printer.SDK is meant for the .NET Framework for building desktop applications. Instead of building your own Webservice, the simplest and easiest way for printing from a web app would be the SendFileToPrinter API, which is a REST API that can be called from anywhere in any programming language. See this article for more details about this API: Use the SendFileToPrinter API for Your Cloud-Based Printing Needs.

R Robert Hamilton

I was able to post-print from a hosted SPA directly to a local printer, but there were a couple of hoops:

  1. Install a certificate on the printer to get around the browser's mixed content (https > http) restriction.
  2. Add the 'mode' property with value 'no-cors' to the request.

Getting the certificate loaded on the printer was the most challenging part. I ended up leveraging Zebra's Print Secure Demo App by replacing the files in the 'demo-certs' folder with my own. I generated the private key and CSR using OpenSSL, and got a wildcard certificate from GoDaddy. When using OpenSSL, be sure the private is produced unencrypted. The file 'HTTPS_KEY.NRD' contains the private key and 'HTTPS_CERT.NRD' contains the certificate. If you do end up using something from a certificate authority, you'll need to add the chain file 'HTTPS_CA.NRD' to the 'demo-certs' folder and update the 'ZEBRA-PRINTSECURE_DEMO_SCRIPT.bat' file to push that file to the printer as well. You can get the contents for the chain file by copying your certificate (PEM) into any certificate chain composer / resolver online. I used this one. You're looking for everything that comes after the certificate you pasted in.

Once I had my certificate on the printer, it printed fine, but I was still getting that error in DevTools. I was able to remove that error with step 2 above. When you do this, CORS is still implemented. This just tells the browser that you're not looking for a response, so it makes the request CORS-safe and doesn't warn that anything was blocked. Note: In this case, CORS doesn't block the request, it blocks the response. You'll still get a 200 OK from the printer though.

CONTACT
Can’t find what you’re looking for?