Cypress.io-是否可以在无头模式下发出CORS请求



测试在标题Chrome中通过。它们在无头Chrome和Electron中失败(有头Electron也失败(。我将Cypress/Plugins文件中的每个浏览器的网络安全标志设置为false。从日志中我可以清楚地看到,飞行前的选项甚至没有制作出来。无头浏览器只返回403 CORS错误。后端服务器甚至没有受到攻击。我想知道是否还有另一种机制在阻止所有无头CORS请求。

在这个SO post 中找到了无头Chrome的解决方案

仍然不知道无头电子。

对于其他Cypress用户:Cypress/plugins/index.js

module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, launchOptions) => {
console.log('..browser ', launchOptions);
if (browser.name === 'chrome') {
launchOptions.args.push('--disable-site-isolation-trials');
launchOptions.args.push('--reduce-security-for-testing');
launchOptions.args.push('--out-of-blink-cors');
return launchOptions;
}
if (browser.name === 'electron') {
launchOptions.preferences.webPreferences.webSecurity = false;
return launchOptions;
}
});

最新更新