Debugging cross domain javascript

Submitted on Sat, 01/21/2012 - 10:46

As I have briefly mentioned in an earlier post, you can easily post to your Drupal site from a phonegap app. The reason for this is that the cross domain browser restriction does not apply for the apps you are building because it is basically a local file (the file:// protocol). While this is really swell, you don't actually develop on your phone, so it would be practical to try out all this in your browser before you deploy to your phone.

If you try it in your browser it will most likely give you "Origin null is not allowed by Access-Control-Allow-Origin." or just a silent fail if you are using jQuery. For example your success function does not get called in your $.ajax. So how do you do cross-domain javascript on your computer?

There might be more methods, but the far easiest I have found I to start chrome with the following parameter: "--disable-web-security". On mac, the parameter is "--args --disable-web-security". If you are using windows, you can just make a shortcut to chrome, edit the "target" in the shortcut to include --disable-web-security in the end, for example "C:\Users\myuser\AppData\Local\Google\Chrome\Application\chrome.exe --disable-web-security". Remember to name it differently so you don't accidently surf the web with cross-domain disabled. Now that you have this in place, go ahead and make awesome apps to post to your Drupal site. Or just wait around for my boilerplate template coming soon.