处理浏览器跨域访问本地http服务报错的问题:
报错详细内容:
The request client is not a secure context and the resource is in more-private address space local
.
处理办法:
- Edge浏览器
- 打开 Edge 浏览器,在地址栏输入
edge://flags/
并按下回车键,进入浏览器的实验性功能设置页面。 - 在搜索框中输入
block-insecure-private-network-requests
,然后找到该选项。 - 将该选项的状态从 “Default” 修改为 “Disabled”。
- 重新启动 Edge 浏览器。
- Chrome浏览器
- 打开Chrome实验功能,在Chrome浏览器地址栏输入,
chrome://flags/
,访问。或者在地址栏输入:chrome://flags/#block-insecure-private-network-requests
- 找到
Block insecure private network requests.
并且禁用
生成一个可以运行的程序或者批处理文件来自动设置浏览器的配置
创建一个批处理文件(.bat),将下面的代码粘贴到其中:
@echo off
echo Setting up Edge browser...
start msedge://flags/
timeout /t 5 /nobreak
echo Please navigate to the experimental features settings page.
timeout /t 5 /nobreak
echo Disabling block-insecure-private-network-requests...
reg add "HKCU\Software\Policies\Microsoft\Edge" /v BlockInsecurePrivateNetworkRequests /t REG_DWORD /d 0 /f
echo Restarting Edge browser...
start msedge://restart
echo Setting up Chrome browser...
start chrome://flags/
timeout /t 5 /nobreak
echo Please navigate to the experimental features settings page.
timeout /t 5 /nobreak
echo Disabling block-insecure-private-network-requests...
reg add "HKCU\Software\Policies\Google\Chrome" /v BlockInsecurePrivateNetworkRequests /t REG_DWORD /d 0 /f
echo Restarting Chrome browser...
start chrome://restart
echo Configuration complete.
pause
请注意,这个脚本需要管理员权限才能生效。运行后,它会依次打开 Edge 和 Chrome 的实验性功能设置页面,然后通过注册表编辑禁用 block-insecure-private-network-requests
选项,并最后重新启动浏览器。最后,脚本会显示 “Configuration complete.” 并等待用户按下任意键结束。