inf3rno
inf3rno

Reputation: 26137

Is it possible to --disable-web-security on Travis Chrome?

I am developing a project which requires --disable-web-security for testing. I use Karma with the following settings:

    browsers: [
        "ch"
    ],
    customLaunchers: {
        "ch": {
            "base": "Chrome",
            "flags": ["--disable-web-security"]
        }
    },

and

if (process.env.TRAVIS)
    options.customLaunchers.ch.flags.push("--no-sandbox");

This works properly on localhost with Chrome v69.0.3497.100 win7 x64.

I am trying to run the same code on Travis (by pushing the changes to GitHub) with the following yml:

language: node_js
node_js:
  - "9"
before_install:
  - export CHROME_BIN=chromium-browser
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
  - sleep 5

I guess we are talking about 2 different browsers with the same engine here, since Chromium != Chrome, but I am not sure. Anyways, I got an error message by trying to build on Travis:

Blocked a frame with origin "http://localhost:9876" from accessing a cross-origin frame.

That clearly indicates that web security is enabled. Is there any way to disable web security on Travis?

Solution:

Using Trusty with real Chrome solved it:

language: node_js
node_js:
  - "9"
dist: trusty
addons:
  chrome: stable
before_install:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
  - sleep 5

Upvotes: 1

Views: 798

Answers (1)

Maël Pedretti
Maël Pedretti

Reputation: 784

According to this documentation you can run Chrome headless by writing the following in your .travis.yml config file

dist: trusty
addons:
  chrome: stable
before_install:
  - # start your web application and listen on `localhost`
  - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

As for your Karma configuration file, check this page. It indicates that you have to add one more flag.

For security reasons, Google Chrome is unable to provide sandboxing when it is running in the container-based environment.

To use Chrome in the container-based environment, pass the --no-sandbox flag to the chrome executable.

module.exports = function(config) {
  config.set({
    browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'],

    // you can define custom flags
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    }
  })
}

Be aware that I have Never done this before. I am just pointing you to the correct documentation.

Upvotes: 2

Related Questions