The new Chrome browser settings allow cross domain implementation

Time:2022-1-2

preface

At present, the front-end solution is cross domain, which is mainly configured through the devserver of webpack. However, sometimes devserver is not configured in the development environment and cross domain is not set on the back end. When you separate the front and back end projects and debug code locally, you often encounter cross domain problems. This article is mainly a supplement to the previous article browser cross domain access solution, because this article finally sets the chrome setting method. At present, the setting does not work. Update the article and correct it.

Solution — Disable web security does not work

In the previous article, the method of setting disable web security for windows, MAC, Linux, etc. was provided, but the security policy of the new version of chrome was upgraded. This opening method or the previous setting method is invalid. So how to solve it?

1、 Set cross domain, right-click “property”, “shortcut” and “target” in the chrome shortcut, click the space at the end of the path, and then add the following code:


--args --disable-web-security --user-data-dir=D:\HaoroomsChromeUserData

perhaps


--disable-web-security --user-data-dir=D:\HaoroomsChromeUserData

D: \ haoroomschromeuserdata is a folder that I can configure myself. If I don’t write this, the settings of the new version of the browser may not take effect

This method means that users create a set of chrome private browser on their computer, and the settings and configurations inside are private settings. At this point, find the chrome installation source directory and open chrome Exe, you will find that all bookmarks and options configured in the private chrome are not available in this chrome.

Note: if you want to delete D: \ haoroms chromeuserdata, you must first make a backup of bookmarks, account passwords, etc. Once deleted, it is equivalent to uninstalling the private chrome in the personal computer, and the data will not be retained

2、 When you open the browser after setting successfully, you will be prompted:

“You are using an unsupported command line tag: — Disable web security, stability and security will be reduced”

At this time, normal users can access across domains, such as local front-end projects, direct connection tests or the interface of online environment (provided that the target environment has logged in in the current browser and there are cookies, sessions and other information of the current account)

3、 Some users still can’t access it. At this time, you will see a paragraph of words with yellow background in the console

‘…Specify SameSite=None and Secure if the cookie should be sent in cross-site…’

At this time, the browser still restricts the cross domain access of cookies, so some people’s computers still can’t use cross domain access,

Solution:

Address field input:

chrome://flags

Re search:

SameSite by default cookies

Find ‘samesite by default cookies’ and’ cookies without samesite must be secure ‘. There is a drop-down box at the back. Select’ disabled ‘for both options, and the browser will prompt in red: “warning: you want to use an experimental function!”

Select ignore the warning. At this time, the browser is D: \ haoromscromeuserdata created locally. Click the relaunch button in the lower right corner, and the browser will restart automatically and keep all currently open pages.

Note: this mode is used for joint debugging. If you visit other shopping websites, it is recommended to use chrome Exe install chrome.exe in the source directory Exe to avoid unnecessary trouble

Other systems:

Mac, like Linux, the original command line does not work. It also specifies a folder for storing data to achieve cross domain effect.

Other solutions

The temporary plug-in solution can be implemented by using chrome.

Search chrome plug-ins

Allow-Control-Allow-Origin: *

After installing the plug-ins, look at their documentation and set the address to be accessed across domains.

This is the end of this article about the cross domain implementation allowed by the new Chrome browser settings. For more relevant cross domain content allowed by chrome, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!