Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protractor - launch chrome with to disable web security for cors

So our application works in production with a CORS enabled.

I have a project that isn't CORS enabled locally. Is there a way to disable web security for protractor? Is there a way for me to add arguments to the selenium instance ?

We're looking for a configuration based solution. Our local development machines are pretty locked down on what we can install. So is this possible?

What i have tried is setting chrome options: https://github.com/angular/protractor/issues/175

But that appears to only be used for chrome extensions.

like image 665
chrisjlee Avatar asked Oct 13 '15 21:10

chrisjlee


People also ask

How do I disable disabling CORS browser?

How do I disable CORS in Windows 10 chrome? Right click on desktop, add new shortcut. Add the target as "[PATH_TO_CHROME]\chrome.exe" –disable-web-security –disable-gpu –user-data-dir=~/chromeTemp. Click OK.

How do I disable CORS check?

You can disable CORS checks in your browser completely. To disable CORS checks in Google Chrome, you need to close the browser and start it with the --disable-web-security and --user-data-dir flags. By doing that, Google Chrome will not send CORS preflight requests and will not validate CORS headers.

How do I run chrome insecure mode?

Right-click the Google Chrome desktop icon (or Start Menu link). Select Properties. At the end of the existing information in the Target field, add: " --allow-running-insecure-content" (There is a space before the first dash.) Click OK.


2 Answers

There is also args inside chromeOptions, where you can provide the --disable-web-security and --user-data-dir arguments.

If you are running the tests locally, make sure to supply a profile location for the --user-data-dir, otherwise Chrome will use the default profile and load the page in the current browser session (running with all of your extensions and settings).

capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'args': ['--disable-web-security', '--user-data-dir=~/.e2e-chrome-profile']
  }
},
like image 125
alecxe Avatar answered Oct 05 '22 11:10

alecxe


@alecxe's solution wasn't working for me. I eventually came up with the following after some cli trial and error; I'm sharing my solution here (it took some hair pulling to figure it out) in case there are other lost souls out there having the same problem:

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ['--disable-web-security', '--user-data-dir']
    }
}

Cheers!

like image 30
Óscar Palacios Avatar answered Oct 05 '22 11:10

Óscar Palacios