12

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.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
chrisjlee
  • 21,691
  • 27
  • 82
  • 112

3 Answers3

24

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']
  }
},
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
2

@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!

Óscar Palacios
  • 511
  • 5
  • 9
0

Worked for me:

chromeOptions: {
      args: ['--disable-web-security','--ignore-certificate-errors']
DeeM
  • 3
  • 2
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30420113) – Joshua Craven Nov 24 '21 at 19:39