slowe / LensToy

A gravitational lens simulator in Javascript/HTML5
5 stars 2 forks source link

Getting started 2: XMLHttpRequest cannot load (FITS) file #2

Closed drphilmarshall closed 12 years ago

drphilmarshall commented 12 years ago

Second error on naive open:

XMLHttpRequest cannot load file://localhost/Users/pjm/work/stronglensing/GalaxyZoo/lenszoo/LensToy/simarc1.fits. Origin null is not allowed by Access-Control-Allow-Origin.

Why isn't the FITS image file being picked up from the current working directory?

Thanks!

Phil

slowe commented 12 years ago

This is only a problem because the webpage is on your local file system and Firefox and Chrome are now paranoid about local file access even within the same directory. I (and others) have reported this in many threads (e.g. http://code.google.com/p/chromium/issues/detail?id=47416) but they won't budge on it. I think I set something in my "about:config" options in Firefox, to allow me to access local files with Javascript, but I can't remember what. If you are using Chrome you will need to start with the option "--allow-file-access-from-files".

slowe commented 12 years ago

OK, I've re-written all the code so that I'm not relying on AJAX to load FITS files. It now simply loads a PNG image. I think the security model may be different for that. Would you update and check if it now works without needing to do anything special to your browser?

drphilmarshall commented 12 years ago

Cool - the simarc image loads, but I see these errors in a standard chrome window:

setup <div id=​"lenstoyholder">​…​

​ lenstoy lenstoy.js:37 draw <canvas style=​"display:​ block;​ " width=​"400" height=​"400" id=​"lenstoy"> lenstoy.js:125

Unable to get image data from canvas because the canvas has been tainted by cross-origin data. Uncaught Error: SECURITY_ERR: DOM Exception 18 lenstoy.js:109 Uncaught TypeError: Cannot set property 'data' of undefined lenstoy.js:116

On Tue, Jul 3, 2012 at 1:44 PM, Stuart reply@reply.github.com wrote:

OK, I've re-written all the code so that I'm not relying on AJAX to load FITS files. It now simply loads a PNG image. I think the security model may be different for that. Would you update and check if it now works without needing to do anything special to your browser?


Reply to this email directly or view it on GitHub: https://github.com/slowe/LensToy/issues/2#issuecomment-6733228

slowe commented 12 years ago

I was just writing an email about this but I'll answer it here to. It seems that the local file paranoia still exists because the image is being drawn to the canvas element. You should be able to get around this in Chrome by starting Chrome with the "--allow-file-access-from-files" flag.

I could try loading the image as a standard HTML img and floating it behind the dynamically-generated image. This solves our local file system problem but also stops us being able to access the pixels of the loaded image. Do we need to know what is in the loaded image?

slowe commented 12 years ago

OK, I have re-written this to show a standard HTML img behind and the lens is simply an overlay with transparency. It is a bit of quick-and-easy workaround for now.

drphilmarshall commented 12 years ago

We do if we want to add the predicted arcs to the background image. If we want to overlay something, we don't need the background image. If this latter option is easier, maybe we should try that and see what it looks like? If the arcs are translucent we might get some of the effect we are after (namely, the arcs looking noisy as well as pixelated).

Cheers

Phil

On Tue, Jul 3, 2012 at 2:01 PM, Stuart reply@reply.github.com wrote:

I was just writing an email about this but I'll answer it here to. It seems that the local file paranoia still exists because the image is being drawn to the canvas element. You should be able to get around this in Chrome by starting Chrome with the "--allow-file-access-from-files" flag.

I could try loading the image as a standard HTML img and floating it behind the dynamically-generated image. This solves our local file system problem but also stops us being able to access the pixels of the loaded image. Do we need to know what is in the loaded image?


Reply to this email directly or view it on GitHub: https://github.com/slowe/LensToy/issues/2#issuecomment-6733584