electron 打包web页面解决跨域问题

在app.whenReady().then(()=>{}),添加

完全禁用同源策略(Same-Origin Policy)
app.commandLine.appendSwitch('--disable-web-security')
禁用 SameSite Cookie 的默认严格模式
app.commandLine.appendSwitch('--disable-features', 'SameSiteByDefaultCookies')
app.commandLine.appendSwitch('--ignore-certificate-errors') // 忽略证书错误
	两行代码。


// 隐藏应用菜单
Menu.setApplicationMenu(null);
app.whenReady().then(() => {
    createWindow()
    app.commandLine.appendSwitch('--disable-web-security')
	app.commandLine.appendSwitch('--disable-features', 'SameSiteByDefaultCookies')

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })

   
})
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐