How do I handle CORS with html2Canvas and AWS S3 images?

前端 未结 2 1736
时光取名叫无心
时光取名叫无心 2021-02-05 22:27

I know similar questions have been asked before but I still can\'t make it work. I have a div with images inside of it loaded from a bucket in AWS s3, they load per

2条回答
  •  再見小時候
    2021-02-05 23:02

    See the edit, I did try setting the crossOrigin attribute with no luck, and I use useCORS set to true (forgot to mention that sorry). Still no luck.

    I fixed some cors issues I was having with the combination of Google Chrome, AWS S3, and multiple origins.

    I found this stackoverflow thread: Chrome + CORS + cache - requesting same file from two different origins

    Which links to this bug report: https://bugs.chromium.org/p/chromium/issues/detail?id=260239

    Anyhow as workaround solution you can try this modified version of html2canvas: https://gist.github.com/CrandellWS/6bc2078aced496004d7a045e6360f19b

    use the options:

    allowTaint : false,
    useCORS: true
    

    Hope that helps.

    FYI, this will add the current time stamp to cors image urls to sidestep a cache issue I was having on Chrome... https://gist.github.com/CrandellWS/6bc2078aced496004d7a045e6360f19b#file-html2canvas-js-L6838

    Which means it will effect performance by re-downloading those images...

    original post: https://github.com/niklasvh/html2canvas/issues/1544#issuecomment-435640901

提交回复
热议问题