1

I am getting following error in error console, facing this issue for many days, please help.

XMLHttpRequest cannot load "localhost Url". Origin https://mail.google.com is not allowed by Access-Control-Allow-Origin.

My purpose is to get an image from my local server and show this image in gmail compose.
This code is working fine in Firefox and Chrome but not with Safari Extension.

If I use Ninjakit to run this code, it works fine. But, if I create a .safariextz installer, I get this error. It's not even going inside an onload function.

Code is:

GM_xmlhttpRequest({ 
  method: 'GET', 
  url: validURL, // localhost Url 
  headers: { 
    'crossDomain':'true', 
    'Accept': 'application/json', 
    'cache-control':'no-cache, no-store, max-age=0, must-revalidate', 
    'pragma':'no-cache', 
  }, 
  onload: function(responseDetails) { 
    var res = responseDetails.responseText; 
  } 
});
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Deepti
  • 11
  • 2
  • Setup your server to allow Cross-Origin Resource Sharing. On Safari there *might* also be a per-extension setting you must make, on the extensions page, to allow access to localhost and/or `file://` URL's. – Brock Adams May 13 '13 at 11:54
  • I am using Tomcat 7, which allows Cross-origin by default. And what is that per extension setting, can you please elaborate – Deepti May 13 '13 at 12:27
  • Does Tomcat 7 return the CORS headers by default? As for that extension setting, there may not be one. I don't use Safari, but Chrome is similar and has such a setting. In Chrome you can see it at `chrome://extensions/`, next to applicable extensions, in Developer Mode. – Brock Adams May 13 '13 at 13:01
  • Hi Adams, Now I have added following CORS settings in tomcat; – Deepti May 14 '13 at 07:59
  • The CORS you posted doesn't have `mail.google.com`. That's the site you were having trouble with in the question. – Brock Adams May 14 '13 at 09:49

0 Answers0