探索OpenBoardView:硬件工程师的PCB分析利器
2026/5/16 20:40:10
修改Chrome浏览器配置以关闭跨域校验,核心是通过自定义启动参数实现(Chrome无内置图形化开关,需通过启动参数禁用同源策略)。以下是分系统的详细操作步骤,适配2025年最新Chrome版本(需注意:新版本强制要求--user-data-dir参数,否则跨域关闭指令无效)。
操作前必须关闭所有已打开的Chrome窗口(包括后台最小化的进程),否则启动参数无法生效。可通过任务管理器(Windows)/活动监视器(Mac)结束所有Chrome进程。
适合长期本地开发使用,创建专属快捷方式,避免影响日常浏览:
"C:\Program Files\Google\Chrome\Application\chrome.exe""C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir=C:\ChromeDevProfile✅ 关键参数说明:--disable-web-security:核心参数,禁用同源策略(跨域校验);--user-data-dir=C:\ChromeDevProfile:指定独立的用户数据目录(新版本强制要求,否则跨域参数无效),路径可自定义(如C:\ChromeDev)。适合临时测试,无需修改快捷方式:
Win+R,输入cmd打开命令提示符;"C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir=C:\TempChromeDevzhangsan),回车执行:open-n /Applications/Google\Chrome.app/Contents/MacOS/Google\Chrome --args --disable-web-security --user-data-dir=/Users/你的用户名/ChromeDevProfile示例(用户名为lisi):open-n /Applications/Google\Chrome.app/Contents/MacOS/Google\Chrome --args --disable-web-security --user-data-dir=/Users/lisi/ChromeDevProfilegoogle-chrome --disable-web-security --user-data-dir=/home/你的用户名/ChromeDevProfile若命令报错,改用完整路径:/usr/bin/google-chrome --disable-web-security --user-data-dir=/home/你的用户名/ChromeDevProfilehttp://localhost:8080);F12打开开发者工具 → 「控制台」;https://api.xxx.com),若控制台不再出现以下报错,说明配置成功:Access to XMLHttpRequest at 'xxx' from origin 'xxx' has been blocked by CORS policy--user-data-dir参数不可省略:Chrome 90+版本强制要求该参数(指定独立的用户数据目录),否则--disable-web-security完全无效;vite.config.js中配置server.proxy;webpack.config.js中配置devServer.proxy;http-server --cors启动本地服务,自动允许跨域。只需关闭所有Chrome窗口,用未添加参数的默认快捷方式启动Chrome即可,独立数据目录(ChromeDevProfile)不会影响正常浏览数据。