steren / stereo-img

web component to display stereographic pictures on web pages, with VR support
https://stereo-img.steren.fr
Apache License 2.0
22 stars 6 forks source link

Support images from arbitrary origins #14

Open smketterer opened 2 years ago

smketterer commented 2 years ago

Hello, firstly, thank you for your work on this project! I found this project somewhat randomly, searching on Github, so please bear with me.

I'm running into an issue when I started serving my images through S3, that hopefully has an easy fix.

Uncaught (in promise) DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
    at parseStereo (https://cdn.skypack.dev/-/stereo-img@v1.2.0-SvezlHHBimxuzf5wxiFG/dist=es2019,mode=imports/optimized/stereo-img.js:84:128)
    at async HTMLElement.parse (https://cdn.skypack.dev/-/stereo-img@v1.2.0-SvezlHHBimxuzf5wxiFG/dist=es2019,mode=imports/optimized/stereo-img.js:220:25)
    at async HTMLElement.parseImageAndInitialize3DScene (https://cdn.skypack.dev/-/stereo-img@v1.2.0-SvezlHHBimxuzf5wxiFG/dist=es2019,mode=imports/optimized/stereo-img.js:275:5)
    at async HTMLElement.init (https://cdn.skypack.dev/-/stereo-img@v1.2.0-SvezlHHBimxuzf5wxiFG/dist=es2019,mode=imports/optimized/stereo-img.js:292:5)

I poked around a little bit, and apparently you can set an option to allow anonymous cross-origin on the canvas image: https://stackoverflow.com/questions/22097747/how-to-fix-getimagedata-error-the-canvas-has-been-tainted-by-cross-origin-data

Setting the headers as outlined in the answer there is easy to do on my end.

Perhaps there are alternative solutions as well?

Thanks for taking a look.

steren commented 2 years ago

Thanks for reporting. I hadn't try to load an image from a different domain. It's be great to support that since that something regular support.

I will take a closer look, but it seems the server needs to allow CORS and the code might need to be updated with image.crossOrigin = 'anonymous';

steren commented 2 years ago

I reverted the change because it introduced an issue I see https://github.com/steren/stereo-img/issues/15