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

时间:2020-04-10 03:15:19

标签: electron cypress

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

1 个答案:

答案 0 :(得分:1)

在此SO post

中找到了无头Chrome的解决方案

对无头电子仍然一无所知。

对于其他赛普拉斯用户: 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;
    }
});