Disable same origin policy in Chrome

2018-12-30 22:55发布

Is there any way to disable the Same-origin policy on Google's Chrome browser?

This is strictly for development, not production use.

26条回答
栀子花@的思念
2楼-- · 2018-12-30 23:23

For Windows... create a Chrome shortcut on your desktop.
Right-click > properties > Shortcut
Edit "target" path :

"C:\Program Files\Google\Chrome\Application\chrome.exe" --args --disable-web-security

(Change the 'C:....\chrome.exe' to where ever your chrome is located).

et voilà :)

查看更多
刘海飞了
3楼-- · 2018-12-30 23:24

Don't do this! You're opening your accounts to attacks. Once you do this any 3rd party site can start issuing requests to other websites, sites that you are logged into.

Instead run a local server. It's as easy as opening a shell/terminal/commandline and typing

cd path/to/files
python -m SimpleHTTPServer

Then pointing your browser to

http://localhost:8000

If you find it's too slow consider this solution

查看更多
公子世无双
4楼-- · 2018-12-30 23:25

Yep. For OSX, open Terminal and run:

$ open -a Google\ Chrome --args --disable-web-security --user-data-dir

--user-data-dir required on Chrome 49+ on OSX

For Linux run:

$ google-chrome --disable-web-security

Also if you're trying to access local files for dev purposes like AJAX or JSON, you can use this flag too.

-–allow-file-access-from-files

For Windows go into the command prompt and go into the folder where Chrome.exe is and type

chrome.exe --disable-web-security

That should disable the same origin policy and allow you to access local files.

Update: For Chrome 22+ you will be presented with an error message that says:

You are using an unsupported command-line flag: --disable-web-security. Stability and security will suffer.

However you can just ignore that message while developing.

查看更多
琉璃瓶的回忆
5楼-- · 2018-12-30 23:26

FOR MAC USER ONLY

open -n -a /Applications/Google\ Chrome.app --args --user-data-dir="/tmp/someFolderName" --disable-web-security
查看更多
皆成旧梦
6楼-- · 2018-12-30 23:27

For Windows:

  1. Open the start menu
  2. Type windows+R or open "Run"
  3. Execute the following command:

    chrome.exe --user-data-dir="C://Chrome dev session" --disable-web-security
    

For Mac:

  1. Go to Terminal
  2. Execute the following command:

    open /Applications/Google\ Chrome.app --args --user-data-dir="/var/tmp/Chrome dev session" --disable-web-security
    

A new web security disabled chrome browser should open with the following message:

enter image description here

查看更多
看风景的人
7楼-- · 2018-12-30 23:27

If you are using Google Chrome on Linux, following command works.

google-chrome  --disable-web-security
查看更多
登录 后发表回答