This is the 7th day of my participation in Gwen Challenge

When I was developing a project, I encountered a strange cross-domain problem, which could not be solved no matter how I wrote the cross-domain solution. Later, I solved this cross-domain problem through the Settings of Chrome browser.

Through the Settings of Chrome browser, there is no need to set the proxy in the project to solve the cross-domain problem. You can directly modify the Settings of Chrome browser to solve the cross-domain problem. Specific cross-domain problems are as follows:

Access to XMLHttpRequest at 'https://weixin.xxx.com/ems/login' (redirected from 'http://localhost:8081/xxx/queryBalance') from origin 'http://localhost:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Copy the code

So next to share the operation steps of the above situation, here is based on the Mac environment, the setting method of other computer operating system is not too much here, if there is a setting method of other computer operating system, please find Baidu. Before setting up cross-domain configuration in Chrome, type the following command line on your Mac terminal.

1. Open the Mac terminal and type the following command line:

open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/ your Mac user name /MyChromeDevUserData/Copy the code

Press enter.

When you open Chrome for the first time, you will see the “You are using an unsupported command line flag: –disable-web-security” with a yellow background. There will be less stability and less safety.” If the command line above is executed again, there will be no more relevant prompts, but you can still cross the domain. After setting Chrome on the CLI, you need to set other options by directly opening Chrome on a Mac. The detailed steps are as follows:

2. Open Chrome, enter Chrome ://flags in the browser address bar, and press Enter.

3. Enter the following text directly into the search bar of your browser:

SameSite by default cookies 
Copy the code

Then press Enter, the search results show the following two options, and then directly disable the two Settings, that is, change the status to Disabled, and then click relaunch in the lower right corner to restart the browser, as shown below:

4. In general, the above operations can solve the cross-domain problem through the browser, but in special cases, the above steps still cannot set the cross-domain problem, then continue to enter the following content in the search box of the browser:

Schemeful Same-Site 
Copy the code

Press Enter to disable this option, set the status to Disabled, and restart the browser.

After the above steps, the perfect implementation of Chrome browser Settings to solve cross-domain problems, this method for the front-end development process encountered cross-domain problems to provide a very effective solution, convenient and easy to use. This cross-domain solution is a very good choice for the front-end white.

The above is all the content of this chapter. Welcome to pay attention to the wechat public account of Sanzhan “Program Ape by Sanzhan”, and the Sina Weibo account of Sanzhan “Sanzhan 666”, welcome to pay attention!