dom-to-image icon indicating copy to clipboard operation
dom-to-image copied to clipboard

CORS problem

Open komitoff opened this issue 2 years ago • 0 comments

Hello there, I am not sure if my issue is a real issue or more like a discussion question. I read a lot of open/closed issues, but didn't really find an answer. I am using the library in order to create screenshot of my webpage. I am running into the well known issue with CORS.

Here is my code:

domtoimage.toJpeg(document.body, { cacheBust: true } )
    .then(function (dataUrl) {
		console.log(dataUrl);
        var link = document.createElement('a');
        link.download = 'my-image-name.jpeg';
        link.href = dataUrl;
        link.click();
	link.remove();
});

When I run this simple code, in the console I am getting a lot of errors like: Access to XMLHttpRequest at 'https://some-url/blue.png?1659515343717' from origin 'http://localhost:8044' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

dom-to-image.min.js:2 cannot fetch resource: https://some-url/blue.png?1659515343717, status: 0

So I added the written option parameter cacheBust and nothing changed. I saw a lot of people are suggesting using a proxy server in order to avoid this error. But I didn't really understand what this server is supposed to do. I found some predefined proxy servers, but how can I provide a proxy server to my code ?

Thanks in advance!

komitoff avatar Aug 03 '22 08:08 komitoff