代码之家  ›  专栏  ›  技术社区  ›  inf3rno

是否可以——在Travis Chrome上禁用Web安全性?

  •  0
  • inf3rno  · 技术社区  · 7 年前

    我正在开发一个需要 --disable-web-security 用于测试。我在以下设置中使用业力:

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

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

    这在使用chromeV69.0.3497.100win7 x64的本地主机上正常工作。

    我尝试在Travis上使用以下YML运行相同的代码(通过将更改推送到GitHub):

    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
    

    我想我们这里讨论的是两种不同的浏览器,它们有相同的引擎,因为 Chromium != Chrome 但是我不确定。总之,我尝试在Travis的基础上建立一个错误消息:

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

    这清楚地表明启用了Web安全性。有没有办法在Travis上禁用网络安全?

    解决方案:

    用真正的Chrome解决了这个问题:

    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
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Maël Pedretti    7 年前

    根据 this documentation 您可以通过在您的 .travis.yml 配置文件

    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 &
    

    至于你的业力配置文件,请检查 this page . 它表示您必须再添加一个标志。

    出于安全原因,Google Chrome无法在基于容器的环境中运行时提供沙盒。

    要在基于容器的环境中使用chrome,请将--no sandbox标志传递给chrome可执行文件。

    module.exports = function(config) {
      config.set({
        browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'],
    
        // you can define custom flags
        customLaunchers: {
          ChromeHeadlessNoSandbox: {
            base: 'ChromeHeadless',
            flags: ['--no-sandbox']
          }
        }
      })
    }
    

    要知道我有 从未 以前做过。我只是指给你正确的文件。