Due to a lot of recent questions about my blog on Http POST printing, I'm posting this notification about CORS. I've been doing a lot of research and testing to try and figure out how and why many people are having issues printing using the Javascript I posted.  Specifically they are getting an error from their browsers "Access-Control-Allow-Origin header not found".  This is a HTTP header element that the third party server (in this case the printer) needs to respond with in order for the browser to know it's OK to call on it if the originating web-server is different.  This security feature is called CORS.  On PC's, most browsers are throwing the error in the console, but still allowing the communication through to the printerThe browsers on OSx machines and Apple products in general are blocking the communications due to this security restriction.  I'm sorry to say I missed this in my testing of the sample code.

 

CORS is a fairly recent security standard. We are exploring our options for handling it. If you are having a specific use case where this seems to be a problem, please comment below or email me directly.  Please make sure to mention the OS, browser, and printer models you are using.  This is so Zebra can correctly prioritize this issue.

 

There are several ways around the problem.  If your website is local to the browsers and printers it will be serving, you can (as posted in a comment from Jan Schinacher to my original post) take the ip address and, on the server, open a TCP socket or Telnet session to port 9100 or 6101 and send the data directly to the printer.  This is my recommended option for local sites as it allows full bi-directional communication (you can check if the printer is in a good state to print).  If the site is hosted elsewhere, there are still a couple of options as I've mentioned in earlier posts.  You can create a Zebra Weblink server for your webserver.  You can create a browser extension. The security is less tight, so most of them I've found will allow the communication through.   If the issue is found on Zebra mobile devices (as in MC75A, or TC55) then you can use our new Enterprise Browser with it's built in printing API's.  Other mobile devices will likely need an app to handle the printing communications.  We have a partner, Arrowhead, that makes a nice iOS app called MobiPrint

 

I hope this helps, and again my apologies for posting code that does not work for everyone.  I'm going to leave it up as it still is useful many developers for now.

 

Robin West

Solution Architect

Zebra ISV and Global Partners Technical