9

I'm trying to follow a melonJS tutorial. It says I should disable cross-origin request using one of two methods:

--disable-web-security

--allow-file-access-from-files**

I've tried both of these in my command prompt as such:

C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --allow-file-access-from-files

C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --disable-web-security

When I try to run the game in Chrome I'm still getting this error:

XMLHttpRequest cannot load file:///C:/Users/danniu/Desktop/JavaScript/melonJS/data/map/area01.tmx. Cross origin requests are only supported for HTTP.

What am I doing wrong?

Thanks

user3871
  • 12,432
  • 33
  • 128
  • 268

4 Answers4

13

You need to use both arguments. This is how I run it on my mac.

open -a Google\ Chrome --args --disable-web-security -–allow-file-access-from-files

This is how it should be for windows:

"C:\PathTo\Chrome.exe" –allow-file-access-from-files -disable-web-security
JJJ
  • 2,889
  • 3
  • 25
  • 43
  • so it would look like this? `C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e xe --disable-web-security --allow-file-access-from-files` , then I can just open my game in that new browser window? – user3871 Feb 25 '14 at 21:52
  • You might also need to add the --args parameter – JJJ Feb 25 '14 at 21:53
  • Check out edit. For windows you actually just need to use one dash – JJJ Feb 25 '14 at 21:55
  • 1
    Okay hmm. Still not working. Any way to verify within the new browser window that I've disabled those? – user3871 Feb 25 '14 at 22:03
  • 5
    well one way is you're not getting the cross origin error. But as soon as you open the browser, a yellow bar should appear at the top saying you're in an unsecure mode. Also, make sure to kill all chrome tasks before running that flag. Otherwise it won't work – JJJ Feb 25 '14 at 22:06
3

To disable chrome web security on mac use this command on terminal

$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir="/tmp/chrome_dev_session" --disable-web-security

if $ open -a Google\ Chrome --args --disable-web-security -–allow-file-access-from-files dosen't help

0

You should request through a HTTP protocol

Here's an answer quite simple to do it: https://stackoverflow.com/a/23118676/1585438

Community
  • 1
  • 1
Helder Robalo
  • 1,827
  • 2
  • 13
  • 16
0

The anti-SOP paramters: --disable-web-security -–allow-file-access-from-files

To make the parameters effective, there must not be another instance of chrome running. If you have chrome running already and start a new instance with the anti-SOP parameters, it will have no effect.

When you close chrome, make sure that all instances are closed. This includes instances without GUI as well (task manager is your friend)!

markus
  • 511
  • 1
  • 4
  • 15