Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add browser args #4341

Closed
wojciechsabaj opened this issue May 30, 2019 · 3 comments
Closed

Cannot add browser args #4341

wojciechsabaj opened this issue May 30, 2019 · 3 comments

Comments

@wojciechsabaj
Copy link

Hi,

when I was trying to solve the problem with X-Frame-Options being sent in response from the server, I found a nice solution here:

#1763 (comment)

I have found a way to bypass the iframe issues. Works with the latest Chrome verision 67.0.3396.62

In my plugins/index.js file I have added the following:

module.exports = (on, config) => {
on("before:browser:launch", (browser = {}, args) => {
if (browser.name === "chrome") {
args.push("--disable-features=CrossSiteDocumentBlockingIfIsolating,CrossSiteDocumentBlockingAlways,IsolateOrigins,site-per-process");
args.push("--load-extension=cypress/extensions/Ignore-X-Frame-headers_v1.1");
return args;
}
});
};

It also contained the link to the browser extension that should be able to strip off the offending header. However, when I added this code to my plugins/index.js, I encountered the following error showing up in main Cypress window:

"arg.push is not a function".

I printed out the content of my "args" and it definitely is an object ("push" method is available ONLY for arrays, not for objects):

{ projectRoot: 'XXXXXXXXXXXXXX',
  browsers:
   [ { name: 'chrome',
       family: 'chrome',
       displayName: 'Chrome',
       version: '74.0.3729.131',
       path: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
       majorVersion: '74' },
     { name: 'electron',
       family: 'electron',
       displayName: 'Electron',
       version: '61.0.3163.100',
       path: '',
       majorVersion: '61',
       info: 'Electron is the default browser that comes with Cypress. This is the browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.' } ],
  proxyUrl: 'http://localhost:59356',
  userAgent: null,
  proxyServer: 'http://localhost:59356',
  socketIoRoute: '/__socket.io',
  chromeWebSecurity: false,
  url: 'http://localhost:59356/__/#/tests/integration\\test.js',
  isTextTerminal: false,
  browser:
   { displayName: 'Electron',
     family: 'electron',
     info: 'Electron is the default browser that comes with Cypress. This is the browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.',
     isChosen: true,
     majorVersion: '61',
     name: 'electron',
     path: '',
     version: '61.0.3163.100',
     isHeaded: true,
     isHeadless: false,
},
  x: 1432,
  y: -8,
  width: 1936,
  height: 1216,
  devTools: true,
  minWidth: 100,
  minHeight: 100,
  contextMenu: true,
  partition: 'persist:interactive',
  trackState:
   { width: 'browserWidth',
     height: 'browserHeight',
     x: 'browserX',
     y: 'browserY',
     devTools: 'isBrowserDevToolsOpen' },
  show: true,
  frame: true,
  recordFrameRate: null,
  onPaint: null,
  webPreferences:
   { partition: null,
     chromeWebSecurity: true,
     nodeIntegration: false,
     backgroundThrottling: false } }

I tried to replicate the behaviour of "push" by manually setting the correct "path" but no success.

        args.browser.args = []
        args.browser.args[0] = "--disable-features=CrossSiteDocumentBlockingIfIsolating,CrossSiteDocumentBlockingAlways,IsolateOrigins,site-per-process"
        args.browser.args[1] = "--load-extension=plugins/Ignore-X-Frame-headers_v1.1"
        args.browser.args[2] = "--disable-web-security"
        args.args = []
        args.args[0] = "--disable-features=CrossSiteDocumentBlockingIfIsolating,CrossSiteDocumentBlockingAlways,IsolateOrigins,site-per-process"
        args.args[1] = "--load-extension=plugins/Ignore-X-Frame-headers_v1.1"
        args.args[2] = "--disable-web-security"

I do not know if something has changed during the development process but please review the examples on your page:

https://docs.cypress.io/api/plugins/browser-launch-api.html#Modify-args-based-on-browser

@flotwig
Copy link
Contributor

flotwig commented May 30, 2019

Electron args are an object, but you can still add command line args to the additionalArguments key, see: #4029 (comment)

@wojciechsabaj
Copy link
Author

@flotwig ok, got it. Please add this information to your documentation (or just link #4029 in there), as this is not intuitive and can save other people a lot of time. I hope that after setting the correct path, all Chrome settings will work with Electron as well.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented May 31, 2019

@wojciechsabaj This is mentioned in the docs

args may be an array or an object (based on the type of browser we’re launching). Whatever you return from this event will become the new args for launching the browser.

But, I will update this to be a comment included in the example.

Edit: changed here: cypress-io/cypress-documentation@fadf8bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants