tsayen / dom-to-image

Generates an image from a DOM node using HTML5 canvas
Other
10.32k stars 1.68k forks source link

Failed to print WMS #198

Open JePedrosa opened 6 years ago

JePedrosa commented 6 years ago

Use case: description, code

Hi, I am using a plugin in leflet that uses dom_to_image to generate an image to later download it or put it in a PDF file and it generates them perfectly until it passes a div that contains a WMS image that then gets stuck and does not return any image, as an error it gives me that isTrusted = true. Then I send an example so that it can be better appreciated. Thank you

https://jsfiddle.net/JesusPedrosa/qu5d43wL/

Browsers

Syndesi commented 6 years ago

Hi,

thank you for the detailed demo, now we can actually help you :) And in fact, I allready found the reason: CORS. Basically you want to display stuff from a different domain http://www.idemap.es/... and want to display it on a secure website (HTTPS). The browser will let you do that, but will mark the data as "mixed content", therefore operations which might be insecure are canceled. If you change the URL to https://www.idemap.es/... (HTTPS instead of HTTP, line 31 in your JSFiddle), you can actually resolve your primary error. And that leads us to CORS: Content served from idemap.es don't have the Access-Control-Allow-Origin HTTP-attribute, therefore further execution is stoped too :/ At this point I only knew three solutions:


resolves #189

JePedrosa commented 6 years ago

Thank you very much for your response, after doing several tests and researching CORS, I think the error is in how I said it does not have the Access-Control-Allow-Origin attribute and therefore it will not let me, I will try to contact them In case you can give me a solution.

Thank you

Syndesi commented 6 years ago

Hi,

I think that Access-Control-Allow-Origin: * should be enough, but I'm not an expert with CORS. I just ran into similar problems and solved them with my own PHP-library. Btw, I created a new Fiddle which uses Mapbox's tilelayers and it actually works: Fiddle But make sure to use your own Mapbox account in production, because it's currently using my credentials which might change sometime.