qq15725 / modern-screenshot

📸 Quickly generate image from DOM node using HTML5 canvas and SVG
https://toolpkg.com/html-to-image
MIT License
504 stars 36 forks source link

How do I manage cors with images? #32

Closed jakedaleweb closed 1 year ago

jakedaleweb commented 1 year ago

When creating a PNG from the dom where a cross-origin image is in-use, am I able to bypass CORS so that the image renders?

For example in html2canvas I can set useCors (html2canvas(screenshotTarget, {useCORS: true})) - is there an equivalent in this library?

qq15725 commented 1 year ago

Use fetch options https://github.com/qq15725/modern-screenshot/blob/v4.4.26/src/options.ts#L83

domToPng({
  fetch: {
    // see https://developer.mozilla.org/en-US/docs/Web/API/fetch
    requestInit: {
      mode: 'cors',
    }
  }
})

Default fetch options https://github.com/qq15725/modern-screenshot/blob/v4.4.26/src/get-default-request-init.ts