electron27版本,使用loadURL页面,出现CORS policy错误解决方案。
Access to XMLHttpRequest at 'http://localhost:8008/paths...' from origin 'http://www.exmaple.com' has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space `local`.
github issue中给出的解决方案,这里我是使用以下代码解决的这个问题。
# 这里的代码要放在ready之前执行。也就是尽早执行这段代码。
app.commandLine.appendSwitch('disable-features', 'BlockInsecurePrivateNetworkRequests,PrivateNetworkAccessSendPreflights');
如果是chrome浏览器的话,需要禁用flag,链接:chrome://flags/#block-insecure-private-network-requests
默认值是default,改为Disabled并重启浏览器。
复制请注明出处,在世界中挣扎的灰太狼