资讯专栏INFORMATION COLUMN

【譯】Chrome Launcher npm v0.3.2

阿罗 / 2260人阅读

摘要:本文翻譯自原文更新時間譯者從輕鬆啟動。禁用了許多服務,他們對於自動化情景是無用的。自動定位二進制文件的位置進行啟動。每次啟動都使用一個新的,並在中清除它。對於可配置性的細節,提供一些設置選項。然後在中,像這樣使用它

本文翻譯自:Chrome Launcher
原文更新時間:July 21,2017
譯者:Pandorym

從 Node 輕鬆啟動 Google Chrome。

禁用了許多 Chrome 服務,他們對於自動化情景是無用的。

在一個可用的端口上,打開瀏覽器的remote-debugging-port

自動定位 Chrome 二進制文件的位置進行啟動。

每次啟動都使用一個新的 Chrome profile,並在kill()中清除它。

綁定Ctrl-C(默認的)終止該 Chrome 進程。

對於可配置性的細節,提供一些設置選項。

安裝

</>复制代码

  1. yarn add chrome-launcher
  2. # or with npm:
  3. npm install chrome-launcher
API .launch([opts])

啟動選項

</>复制代码

  1. {
  2. // (optional) remote debugging port number to use. If provided port is already busy, launch() will reject
  3. // Default: an available port is autoselected
  4. port: number;
  5. // (optional) Additional flags to pass to Chrome, for example: ["--headless", "--disable-gpu"]
  6. // See all flags here: http://peter.sh/experiments/chromium-command-line-switches/
  7. // Do note, many flags are set by default: https://github.com/GoogleChrome/lighthouse/blob/master/chrome-launcher/flags.ts
  8. chromeFlags: Array;
  9. // (optional) Close the Chrome process on `Ctrl-C`
  10. // Default: true
  11. handleSIGINT: boolean;
  12. // (optional) Explicit path of intended Chrome binary
  13. // If the `CHROME_PATH` env variable is set, that will be used
  14. // Usage of `LIGHTHOUSE_CHROMIUM_PATH` env variable is deprecated
  15. // By default, any detected Chrome Canary or Chrome (stable) will be launched
  16. chromePath: string;
  17. // (optional) Chrome profile path to use
  18. // By default, a fresh Chrome profile will be created
  19. userDataDir: string;
  20. // (optional) Starting URL to open the browser with
  21. // Default: `about:blank`
  22. startingUrl: string;
  23. // (optional) Logging level: verbose, info, error, silent
  24. // Default: "info"
  25. logLevel: string;
  26. // (optional) Enable extension loading
  27. // Default: false
  28. enableExtensions: boolean
  29. };
啟動 chrome 后的接口

.launch().then(chrome => ...

</>复制代码

  1. // The remote debugging port exposed by the launched chrome
  2. chrome.port: number;
  3. // Method kill Chrome (and cleanup the profile folder)
  4. chrome.kill: () => Promise<{}>;
  5. // The process id
  6. chrome.pid: number;
Examples 啟動 chrome

</>复制代码

  1. const chromeLauncher = require("chrome-launcher");
  2. chromeLauncher.launch({
  3. startingUrl: "https://google.com"
  4. }).then(chrome => {
  5. console.log(`Chrome debugging port running on ${chrome.port}`);
  6. });
持續集成

在一個想 Travis 這樣的 CI 環境,可能沒有安裝 Chrome。如果你想要使用chrome-launcher,你可以使用 Lighthouse 的download-chrome.sh安裝 Chrome。

</>复制代码

  1. curl -L https://raw.githubusercontent.com/GoogleChrome/lighthouse/v2.1.0/lighthouse-core/scripts/download-chrome.sh | bash

然後在.travis.yml中,像這樣使用它:

</>复制代码

  1. language: node_js
  2. install:
  3. - yarn install
  4. before_script:
  5. - export DISPLAY=:99.0
  6. - export LIGHTHOUSE_CHROMIUM_PATH="$(pwd)/chrome-linux/chrome"
  7. - sh -e /etc/init.d/xvfb start
  8. - curl -L https://raw.githubusercontent.com/GoogleChrome/lighthouse/v2.1.0/lighthouse-core/scripts/download-chrome.sh | bash

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/84468.html

相关文章

  • 】Headless Chrome 入門指南

    摘要:確切位置因平台而異。如果以編程方式使用,這個頁面也是一個強大的調試工具,能看到所有原始的協議命令通過連線,於瀏覽器進行通信。警告協議可以做很多有趣的事,但作為入門選項他令人沮喪。目前,提供了比協議高級別的。 本文翻譯自:Getting Started with Headless Chrome原文更新時間:July 28,2017作者:Eric Bidelman(Engineer @ G...

    toddmark 评论0 收藏0
  • [笔记]1.Karma前端TDD试水

    摘要:起博主是电信行业的码农,在工作单位也搞搞单元测试和了什么。目前对技术很感兴趣,尝试新的领域里面也试试看这次要用的方式要实现一个简单画图板功能,支持和。配置文件里面主要就是一个对象,根据注释提示调整下即可。 起 博主是电信行业的码农,在工作单位也搞搞单元测试和TDD了什么。目前对Web技术很感兴趣,尝试新的领域里面也试试看TDD. 这次要用TDD的方式要实现一个简单画图板功能,支持C...

    894974231 评论0 收藏0
  • chrome-remote-interface

    摘要:該支持下列事件當到的連接已建立時觸發。取得該調試協議描述符。在關閉請求收到響應后執行,他將獲得下列參數一個對象,指明成功狀態當缺省時,將返回一個對象。當缺省時,將返回一個對象,並且狀態取決于屬性。 本文翻譯自:chrome-remote-interface原文更新時間:July 21,2017譯者:Pandorym Chrome 調試協議 的接口,他提供一個使用 JavaScript ...

    lentoo 评论0 收藏0
  • 前端单元测试

    摘要:为保证代码的质量,单元测试必不可少。本文记录自己在学习单元测试过程中的一些总结。以一个项目为例,代码结构如下前端测试框架主要是与,这里我们选择,断言库有以及自带的。 为保证代码的质量,单元测试必不可少。本文记录自己在学习单元测试过程中的一些总结。 TDD与BDD的区别 TDD属于测试驱动开发,BDD属于行为驱动开发。个人理解其实就是TDD先写测试模块,再写主功能代码,然后能让测试模块通...

    liuyix 评论0 收藏0
  • 【Karma】多环境自动测试框架 -- 基础教程

    摘要:介绍前身,创建出来的以下是官网对的相关特点介绍支持真实浏览器无浏览器热更新,文件变化后自动测试测试框架无关性支持开源易测试持续集成安装配置配置项自动监控更新如果为相对路径,则加上作为前缀配合运行浏览器如果浏览器在指定时间 介绍 前身 Testacular, AngularJs Team 创建出来的. 以下是官网对Karma的相关特点介绍 支持真实浏览器, 无浏览器PhantomJS ...

    BaronZhang 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<