dymosoftware / dymo-connect-framework

DYMO Connect Framework for Javascript.
Other
86 stars 54 forks source link

CORS issues #30

Open ethanpil opened 2 years ago

ethanpil commented 2 years ago

If I simply run the JavaScript demos untouched I get CORS errors from Chrome.

dymo.connect.framework.js:2 Access to XMLHttpRequest at 'https://127.0.0.1:41951/DYMO/DLS/Printing/RenderLabel' from origin 'https://XXXXX.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

uzdeveloper1 commented 2 years ago

how can this be fixed ?

cage85 commented 2 years ago

Also experiencing this issue. I assume Dymo Connect Service needs to be updated to return "Access-Control-Allow-Origin: *" in the header on all requests to avoid this issue.

ethanpil commented 2 years ago

I have called DYMO and emailed this address per the phone support sdkreply @ newellco.com Perhaps if we all call and email we might get some attention faster...

magace commented 2 years ago

I was able to find a workaround for chrome. chrome://flags/ disable > Block insecure private network requests.

Not sure on how safe it is, but it got me up and running. I too have reached out to support with no help.

andythedude commented 2 years ago

I was able to find a workaround for chrome. chrome://flags/ disable > Block insecure private network requests.

Not sure on how safe it is, but it got me up and running. I too have reached out to support with no help.

This worked for me. my client was using edge which is based on chrome, i think it might have broken because of this https://developer.chrome.com/blog/private-network-access-update/

ande2407 commented 2 years ago

Also having this issue. I can get it to work right up until the call to print. Turning off browser security seems like the wrong answer. Is Dymo still supporting this framework or not?

ande2407 commented 2 years ago

I was able to find a workaround for chrome. chrome://flags/ disable > Block insecure private network requests.

Not sure on how safe it is, but it got me up and running. I too have reached out to support with no help.

I just tried this, and I still get the CORS error when it tries to issue the print.

To be fair, I also had to use combinatronics to even link the js into the project.

IT seems like they are just letting this die, which is sad. Very useful feature.

cage85 commented 2 years ago

I've recently been trying to reverse-engineer the dymo-connect-framework.js file to solve a new issue that has come up for me - the getPrinter function has suddenly stopped returning printers even though the GetPrinters Web Service endpoint is returning them (I resorted to building a simple Ajax function to fetch the printer from the endpoint directly instead of using the framework's function). The file is in a real messy state and the code seems severely over-engineered. Without attention from Dymo the only hope is if the community takes over ownership and maintenance.

dpolivy commented 2 years ago

I know the DYMO team is a bit overloaded at the moment with the launch of the new LabelWriter 5xx series printers. I will raise this with my contacts there and see if we can get an official response/update.

In the meantime, have you tried going back to the older DYMO Label Software v8.7.4? That's what I'm currently running and it looks like the web service is returning the access-control-allow-origin: * header in the response.

ethanpil commented 2 years ago

Thank you @dpolivy in case they cant get this fixed, I found this page with some higher ups at Dymo and we can try emailing some bosses to get attention... https://www.elliott.org/company-contacts/newell-brands/

dymosoftware commented 2 years ago

Thank you for your patience.

labelwriter.com will be deprecated sooner or later because it is aged server. And labelwriter.com ran into an issue passed into 127.0.0.1 which blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space local.

Javascript SDK works with sample html files with your local framework.js file against your local Web Api without blocking CORS policy with following steps.

We have a shortterm work-around is:

  1. Download dymo.connect.framework.js file and sample files into client's local folder.
  2. Put it in the parent folder for the html.

Dymo.connect.framework.js file is: https://github.com/dymosoftware/dymo-connect-framework

Sample files are: https://github.com/dymosoftware/DCD-SDK-Sample/tree/master/JavaScript

ethanpil commented 2 years ago

Sorry @dymosoftware don't understand. Many of us are printing from a remote server on the web to a local printer. How will this solve the CORS issue of printing from a remote web server https://example.com/dymo.connect.framework.js to DYMO printer on localhost?

I read from @dpolivy that reverting to older version of DYMO connect will work. Where can we find DYMO Label Software v8.7.4 downloads for Mac and Windows?

dpolivy commented 2 years ago

@ethanpil You can find links to the older versions on the Compatibility Chart page here:

https://www.dymo.com/compatibility-chart.html

ande2407 commented 2 years ago

Yeah, that answer doesn't work. I'm not writing a web service to run on my computer to talk to the printer on my computer. I need to be able to have our hosted site send labels to the connected printer.

I'm also not able to include the 'labelwriter' source, as it is not https. I had to use a third party site to convert the raw.github file.

dymosoftware commented 2 years ago

Hi, do you have any link with a sample that we may try on our side to test with web service?

dymosoftware commented 2 years ago

DYMO web api accepts all cross origins as default already, and we had to setup new sample website which fixes CORS issue between http://labelwriter.com and https://127.0.0.1:xxxx or https://localhost:xxxx. http://labelwriter.com will be deprecated sooner or later.

The new sample web pages are found "Sample Html Pages" section in Readme file in https://github.com/dymosoftware/DCD-SDK-Sample.

The same sample html pages links are: https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/CheckEnvironment/CheckEnvironment.html https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/VisitorManagement/VisitorManagement.html https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/PreviewAndPrintLabel/PreviewAndPrintLabel.html

Thank you for your patience.

ande2407 commented 2 years ago

Hey Guys, First off thank you for your response. Moving the script local to the project does work, I also used combinatronics to scrape it from your github. JSDelivr I think does the same thing. That also gets around the https issue but still allows us to grab the framework from you.

ON my issue of the CORS issue when issuing the label.print, that seems to have gone away. My printer stopped being detected, and I had to manually install the driver to a usb port. After that, label.print begain working. The error I was getting back before was rejected due to CORS, but that error might actually have been false?

I'm up and running, so thank you. Not sure if ethanpil is still having the same issue.

cage85 commented 2 years ago

@ande2407 my experience is exactly the same, however I have not managed to get the printer to be detected. You wrote "manually install the driver to a usb port" -- what does that mean, could you explain what you did?

ethanpil commented 2 years ago

@dymosoftware I tried the sample html pages from the AWS links you provided, but they don't even work to detect my printer. At least the demo as I have locally will detect the printer but has the CORS issue.

I'm at a complete loss here, since the suggestions made by @dymosoftware the official developers don't make any sense, and don't address the issues at hand for anyone!

ande2407 commented 2 years ago

@ande2407 my experience is exactly the same, however I have not managed to get the printer to be detected. You wrote "manually install the driver to a usb port" -- what does that mean, could you explain what you did?

Sure. I'm on Windows 10. When going to 'add printers', the Labelwriter 450 turbo would not show up. I would just click, my printer wasn't detected. Then I would 'add it manually' and select the printer manufacturer and model. I created a usb virtual port for it and let it install the driver.

After that it worked, although only on one port. I assume I might have to create a second virtual port for it for my other USB port, but didn't explore it.

I have the latest Dymo Connect software installed.

ande2407 commented 2 years ago

@ethanpil I did my testing in firebase. I was able to load the label printer sample to a hosted app there and get it to work. I only had to change the include for the framework. I used combinatronics to create a cdn from the raw.github. After that it worked.

If you think it is helpful for you, I can set that back up and send you the link. I took it down as it was only for testing before moving to my actual project.

ethanpil commented 2 years ago

Hi, do you have any link with a sample that we may try on our side to test with web service?

I have tried changing the Chrome setting, just to see if it work, it did not. I updated to the latest dymo-connect-framework JavaScript, it did not help.

It's clear to me that @cage85 is correct. The only solution is to release a new verision of Dymo Connect which sends the correct HTTP headers.

Just to be clear, I am using a remote web server with the printer on the local computer.

I am happy to send you a link I do not want to post publicly here.

ande2407 commented 2 years ago

If it helps, here is a link to the dymo sample running, hosted in firebase. The only thing different is how the framework is included.

https://dymo-original.web.app/

This works printing to my machine with a 450 turbo.

ethanpil commented 2 years ago

Sorry, none of these solutions work for me. Here's a screenshot from my chrome which clearly indicated the issue is simply the missing headers from 127.0.0.1 which is the DYMO HTTP server...

image

dpolivy commented 2 years ago

@ethanpil I think the CORS issue might be a red herring here. The original request is returning a 500 error which might indicate some other issue on the system. It's possible (likely?) there's a bug in the web service where it is not including the CORS header when returning a 500 error. If you look at the prior GetPrinters or StatusConnected API calls that succeed, my guess is the CORS header will be there. If you look at the actual response, is there a more detailed error message?

cage85 commented 2 years ago

@dpolivy @ethanpil Yes, I have come to the same conclusion. There is some other error happening which is resulting in a 500 before all the headers are sent. Unfortunately there is no detailed error description to be found anywhere including Dymo Connect Web Service logs. I've spent many hours trying different ways of invoking the print command (label.print, printLabel etc.) and other things but have come up empty. Next I'm going to test different label templates to see if that's the issue.

cage85 commented 2 years ago

After tearing my hair out over this for some time I finally found a solution to my issues. It turns out the label type specified in my label template was not compatible with the language that the DYMO software was installed in. It seems that if DYMO Connect is installed on an English US version of Windows, metric-based label types (e.g. Name badge 54 x 101mm S0722430) will not print. I don't understand why all label types are not supported regardless of OS locale, or why error messages were not printed to DYMO Connect Web Service logs to indicate the issue.

Anyways, as @dpolivy suspected, when trying to print my labels the PrintLabel endpoint would return a 500 before complete headers were returned, which is why the "Access-Control-Allow-Origin: *" was missing. I changed my Windows display language to a metric-based one, reinstalled DYMO Connect, and I was back in business.

@ethanpil I'm not sure if this is your issue as well, but to confirm, open DYMO Connect and check which label types (i.e label sizes) are available, and ensure that the label type used in the sample script is among them. If not, you will get a 500 error.

rfdrake27 commented 2 years ago

DYMO web api accepts all cross origins as default already, and we had to setup new sample website which fixes CORS issue between http://labelwriter.com and https://127.0.0.1:xxxx or https://localhost:xxxx. http://labelwriter.com will be deprecated sooner or later.

The new sample web pages are found "Sample Html Pages" section in Readme file in https://github.com/dymosoftware/DCD-SDK-Sample.

The same sample html pages links are: https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/CheckEnvironment/CheckEnvironment.html https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/VisitorManagement/VisitorManagement.html https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/PreviewAndPrintLabel/PreviewAndPrintLabel.html

Thank you for your patience.

Unfortunately I'm still getting the CORS error even on your sample html pages.

cage85 commented 2 years ago

@rfdrake27 see above, the CORS issue is probably due to another error occurring before the Dymo Connect Web Service has had a chance to send the correct headers.

stormframe commented 2 years ago

Hi, i had exactly the same Issue. WIN10H1 aktuell Dymo .82 Afer Reinstalling the Software it was working on Chrome and Edge

akash-s-simformsolutions commented 2 years ago

image

I am loading label and update label text fields and printing label using latest dymo connect software and windows10 but i am keep getting CORS issue.

tried with Chrome://flags setting but not working.

can anybody please help

grezniczek commented 2 years ago

@dymosoftware it would be really nic if the webservice would handle internal errors properly, i.e. send correct headers from the error handler.

It's really about time this was implemented.

akash-s-simformsolutions commented 2 years ago

image

I am loading label and update label text fields and printing label using latest dymo connect software and windows10 but i am keep getting CORS issue.

tried with Chrome://flags setting but not working.

can anybody please help

Using latest dymo javascript SDK Tried reinstalling label and dymo connect software but no luck. windows service is running on port 41951

https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/CheckEnvironment/CheckEnvironment.html above url shows

isBrowserSupported: true
isFrameworkInstalled: true
isWebServicePresent: true

@ethanpil @stormframe @rfdrake27 @ande2407 @dpolivy Please let me know if any anybody has working solution or any suggestions about above issue.

@dymosoftware ??

cage85 commented 2 years ago

@akash-s-simformsolutions the PrintLabel endpoint is throwing a 500. Maybe your (or Dymos) test page is using a metric-based label type and your Windows installation is non-metric (e.g. US English) or vice-versa.

ErnstWolthaus commented 2 years ago

Hi all,

I've managed to get the Dymo LabelWriter 450 working from Dynamics 365 CE. It took me a while and I thought I also had an issue with CORS.

I debugged the JS lib of Dymo and in the end it turned out to be an error in my label xml. So, the CORS error message might be a 'red herring', meaning if your sending the printer invalid data, you might get the wrong error message... (I think @cage85 also is pointing to this...)

Now my label xml is OK and I have no issues using the Dymo Labelwriter 450. So please make sure your data is correct. (of course, you do need to have the Dymo service running on your local computer)

Good luck! Ernst

akash-s-simformsolutions commented 2 years ago

@cage85 Thanks for sharing details. i will check about label type.

@ErnstWolthaus Thanks for sharing details. I am also trying same with Dymo label Printer 450 4XL. I have created Label using Latest Dymo connect software and i am using that label and updating few dynamic values.

var labelXml = "XML file content geneated by software .dymo file content"
var label = dymo.label.framework.openLabelXml(labelXml);

// Updating some values in label to update it dynamically
label.setObjectText("ITextObject0", "XYZ");
label.setObjectText("ITextObject4", "ABC");

// After updating label i check if its valid or not
label.isValidLabel();  <-- This prints True

// Print label 
label.print("DYMO LabelWriter 4XL");   <--- This is where getting errors.

Also if i do not update label and use as it is which is generated from dymo connect software its giving same issue.

Please check above flow and let me know anything if i am missing. Thanks in advance.

@ErnstWolthaus : If you can share how you created label that would be also helpful.

ErnstWolthaus commented 2 years ago

Hi @akash-s-simformsolutions

  1. the labelXml is not correct... it's not xml, so dymo.label.framework.openLabelXml will not process that.
  2. are you sure the printername is correct?
  3. Is Dymo Connect service up-and-running?

If you are a developer, you can download the full version of the framework and debug into the library to see what's wrong...

I have used this code (changed the labelXml to actual xml, see attachment), and it works for me.

FYI: I have created the label xml with Dymo Connect software. Just create the label and save it to disk. Then use the xml content of that file. Please make sure you are able to print a label with the Dymo Connect software, just to make sure the standard software works...

labelsample.txt

akash-s-simformsolutions commented 2 years ago

Hi @ErnstWolthaus Thanks for quick response and example.

  1. the labelXml is not correct... it's not xml, so dymo.label.framework.openLabelXml will not process that. -> I understood that. i have used proper xml here. but just for understanding i have mentioned that its content of .dymo file, I will try with your label once. Thanks

  2. are you sure the printername is correct? -> Yes i have used dymo's method to get printer name and using same name in code as well.

  3. Is Dymo Connect service up-and-running? -> Yes dymo connect service is up and running.

I will test it with new label and let you know updates.

Thanks.

timint commented 2 years ago

I am too having this CORS issue and can't get around it. This is on both MacOS and Windows with the latest JS framework on Github. Firefox, Chrome and Edge are all affected. Using last DCD software with the last JS library from Github.

This a problem with today's stricter security policies by web browser makers.

VM12:1 Access to XMLHttpRequest at 'https://127.0.0.1:41951/DYMO/DLS/Printing/PrintLabel' from origin 'https://www.domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

The following did not solve my problem:

chrome://flags/#block-insecure-private-network-requests disabled

I figured out why StatusConnected Works https://127.0.0.1:41951/DYMO/DLS/Printing/StatusConnected

Returns true image

And PrintLabel doesn't: image

DYMO needs to consistently add the CORS policy to all server responses, not just some. This should be escalated to the DCD developers.

0xE1 commented 2 years ago

We have same issue as well, the only workaround we managed to work is to use DYMO Label Software 8.5.4 and block DYMO Connect Service from using first port, then it works without issues.

I will see if I can connect debugger to DYMO service to see what it fails on...

timint commented 2 years ago

@0xE1 They are missing the Access-Control-Allow-Origin: * header in the HTTP response for PrintLabel.

0xE1 commented 2 years ago

For every response? Was mentioned "not just some", so it might be that the service just throws an exception for most requests and then response does not include necessary headers.

timint commented 2 years ago

@0xE1 If any DYMO Connect response does not hold an Access-Control-Allow-Origin HTTP header in the response, the browser will return a HTTP 500 error. They implemented it on some responses like /StatusConnected, and /GetPrinters but not /PrintLabel.

They have to compile a new DYMO.WebApi.Win.Host.exe with the fix.

dymosoftware commented 2 years ago

As @ande2407 wrote in previous comments, have you tried to include the script in your web project? https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/dymo.connect.framework.js

timint commented 2 years ago

@dymosoftware This issue ticket is already addressed not to be a user problem. But a problem in DYMO.WebApi.Win.Host.exe. https://github.com/dymosoftware/dymo-connect-framework/issues/30#issuecomment-1012600893

dymosoftware commented 2 years ago

@timint We are beginning to investigate this issue. Thanks for your help so far diagnosing it.

timint commented 2 years ago

@dymosoftware I am very delighted to hear this. So are my clients. 👍 🙂

xd-luke commented 2 years ago

@dymosoftware it has been over a week. How long does it take your developers to add this one header? Our project is currently stalled because of this issue. Can you please provide an accurate time estimate? We need to make a decision to downgrade versions to get this working in our systems. We would prefer not to downgrade for obvious reasons. If this will be fixed soon we will wait. But, if not, we have not other choice but to downgrade.

andythedude commented 2 years ago

I don't think it's a high priority for them. Seems as if all their focus is on the actual printers and the printer desktop software, whereas a library like this is an afterthought. It took them almost 3 months to even start working on this so i wouldn't count on them fixing it with any degree of urgency.

dymosoftware commented 2 years ago

Hi all, could you try to run your app with this preview version of DLSSidecar_1.4.3-147-beta-WS.exe installed?

Let us know if you still have issues with API headers.