chromeless README

The project's README from github.com/schickling/chromeless. As one markdown file: README.md.

This project is deprecated in favor for Puppeteer. Thanks to all the contributors who made this project possible.

Chromeless

npm downloads circleci codecov dependencies node semantic-release

Chrome automation made simple. Runs locally or headless on AWS Lambda. (See Demo)

Chromeless can be used to...

Examples

▶️ Try it out

You can try out Chromeless and explore the API in the browser-based demo playground (source).

Contents

  1. How it works
  2. Installation
  3. Usage
  4. API Documentation
  5. Configuring Development Environment
  6. FAQ
  7. Contributors
  8. Credits
  9. Help & Community

How it works

With Chromeless you can control Chrome (open website, click elements, fill out forms...) using an elegant API. This is useful for integration tests or any other scenario where you'd need to script a real browser.

There are 2 ways to use Chromeless

  1. Running Chrome on your local computer
  2. Running Chrome on AWS Lambda and controlling it remotely

1. Local Setup

For local development purposes where a fast feedback loop is necessary, the easiest way to use Chromeless is by controlling your local Chrome browser. Just follow the usage guide to get started.

2. Remote Proxy Setup

You can also run Chrome in headless-mode on AWS Lambda. This way you can speed up your tests by running them in parallel. (In Graphcool's case this decreased test durations from ~20min to a few seconds.)

Chromeless comes out of the box with a remote proxy built-in - the usage stays completely the same. This way you can write and run your tests locally and have them be executed remotely on AWS Lambda. The proxy connects to Lambda through a Websocket connection to forward commands and return the evaluation results.

Installation

npm install chromeless

Proxy Setup

The project contains a Serverless service for running and driving Chrome remotely on AWS Lambda.

  1. Deploy The Proxy service to AWS Lambda. More details here
  2. Follow the usage instructions here.

Usage

Using Chromeless is similar to other browser automation tools. For example:

const { Chromeless } = require('chromeless')

async function run() {
  const chromeless = new Chromeless()

  const screenshot = await chromeless
    .goto('https://www.google.com')
    .type('chromeless', 'input[name="q"]')
    .press(13)
    .wait('#resultStats')
    .screenshot()

  console.log(screenshot) // prints local file path or S3 url

  await chromeless.end()
}

run().catch(console.error.bind(console))

Local Chrome Usage

To run Chromeless locally, you need a recent version of Chrome or Chrome Canary installed (version 60 or greater). By default, chromeless will start Chrome automatically and will default to the most recent version found on your system if there's multiple. You can override this behavior by starting Chrome yourself, and passing a flag of launchChrome: false in the Chromeless constructor.

To launch Chrome yourself, and open the port for chromeless, follow this example:

alias canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary"
canary --remote-debugging-port=9222

Or run Chrome Canary headless-ly:

canary --remote-debugging-port=9222 --disable-gpu --headless

Or run Chrome headless-ly on Windows:

cd "C:\Program Files (x86)\Google\Chrome\Application"
chrome --remote-debugging-port=9222 --disable-gpu --headless

Proxy Usage

Follow the setup instructions here.

Then using Chromeless with the Proxy service is the same as running it locally with the exception of the remote option. Alternatively you can configure the Proxy service's endpoint with environment variables. Here's how.

const chromeless = new Chromeless({
  remote: {
    endpointUrl: 'https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com/dev',
    apiKey: 'your-api-key-here',
  },
})

API Documentation

Chromeless constructor options

Chromeless methods

Chrome methods

Configuring Development Environment

Requirements:

  1. Clone this repository
  2. Run npm install
  3. To build: npm run build

Linking this NPM repository

  1. Go to this repository locally
  2. Run npm link
  3. Go to the folder housing your chromeless scripts
  4. Run npm link chromeless

Now your local chromeless scripts will use your local development of chromeless.

FAQ

How is this different from NightmareJS, PhantomJS or Selenium?

The Chromeless API is very similar to NightmareJS as their API is pretty awesome. The big difference is that Chromeless is based on Chrome in headless-mode, and runs in a serverless function in AWS Lambda. The advantage of this is that you can run hundreds of browsers in parallel, without having to think about parallelisation. Running integration Tests for example is much faster.

I'm new to AWS Lambda, is this still for me?

You still can use this locally without Lambda, so yes. Besides that, here is a simple guide on how to set the lambda function up for Chromeless.

How much does it cost to run Chromeless in production?

The compute price is $0.00001667 per GB-s and the free tier provides 400,000 GB-s. The request price is $0.20 per 1 million requests and the free tier provides 1M requests per month.

This means you can easily execute > 100.000 tests for free in the free tier.

Are there any limitations?

If you're running Chromeless on AWS Lambda, the execution cannot take longer than 5 minutes which is the current limit of Lambda. Besides that, every feature that's supported in Chrome is also working with Chromeless. The maximal number of concurrent function executions is 1000. AWS API Limits

Are there commercial options?

Although Chromeless is the easiest way to get started running Chrome on Lambda, you may not have time to build and manage your own visual testing toolkit. Commercial options include:

Troubleshooting

Error: Unable to get presigned websocket URL and connect to it.

In case you get an error like this when running the Chromeless client:

{ HTTPError: Response code 403 (Forbidden)
    at stream.catch.then.data (/code/chromeless/node_modules/got/index.js:182:13)
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)
  name: 'HTTPError',
...
Error: Unable to get presigned websocket URL and connect to it.

Make sure that you're running at least version 1.19.0 of serverless. It is a known issue, that the API Gateway API keys are not setup correctly in older Serverless versions. Best is to run npm run deploy within the project as this will use the local installed version of serverless.

Resource ServerlessDeploymentBucket does not exist for stack chromeless-serverless-dev

In case the deployment of the serverless function returns an error like this:

  Serverless Error ---------------------------------------

  Resource ServerlessDeploymentBucket does not exist for stack chromeless-serverless-dev

Please check, that there is no stack with the name chromeless-serverless-dev existing yet, otherwise serverless can't correctly provision the bucket.

No command gets executed

In order for the commands to be processed, make sure, that you call one of the commands screenshot, evaluate, cookiesGetAll or end at the end of your execution chain.

Contributors

A big thank you to all contributors and supporters of this repository 💚

joelgriffith adieuadieu schickling timsuchanek Chrisgozd criticalbh d2s emeth- githubixx hax Hazealign joeyvandijk liady matthewmueller seangransee sorenbs toddwprice vladgolubev

Credits

Help & Community Slack Status

Join our Slack community if you run into issues or have questions. We love talking to you!

Prisma

chromeless (schickling/chromeless)

Searching Database…

13.2K ·GitHub
archived
这是什么?Chromeless 是一个 TypeScript 库,可以用代码自动化操作 Chrome:打开网页、点击元素、填写表单、截图。注意它现在已经停止维护,官方推荐改用 Puppeteer。
它是一个写代码时调用的库,还是一个要部署的服务?两者都是。它是一个 npm 库,可以在 Node.js 脚本中调用;同时还附带一个远程 proxy,可以部署到 AWS Lambda,让 Chrome 在云端无界面运行,而你的代码留在本地。
怎么把它跑起来?安装这个 npm 包,然后在 Node.js 脚本里引入它——Chromeless 会自动启动你本地的 Chrome。如果想用云端模式,需要先用 Serverless 框架把自带的 proxy 服务部署到 AWS Lambda。
要用它,我需要装哪些东西?需要较新版本的 Chrome 或 Chrome Canary(60 及以上),以及 Node.js(开发环境要求 8.2 或更新)。如果用 Lambda 模式,还需要一个 AWS 账号和 Serverless 框架 1.19.0+。
这个项目还在维护吗,还是我应该找别的方案?它已经废弃,代码仓库也已归档——README 推荐 Puppeteer 作为替代品。已有的脚本仍然能跑,但别指望有新功能或修复。
我实际能用它来做什么?并行运行大批量的浏览器集成测试、抓取网页和批量截图,以及搭建需要真实浏览器的机器人——也就是过去用 PhantomJS、NightmareJS 或 Selenium 做的那些活儿。
它和 Selenium、NightmareJS 有什么不同?它的 API 刻意设计得和 NightmareJS 很接近,但 Chromeless 驱动的是真正的无界面 Chrome,而且可以跑在 AWS Lambda 函数里。这意味着不用自己处理并行化,就能同时运行几百个浏览器——Graphcool 把测试时间从大约 20 分钟缩短到了几秒。
这个 API 具体都能做什么?可以跳转网页、点击、输入文字、等待元素出现、滚动、设置视口和 HTTP 头、管理 cookie 和缓存、截图和生成 PDF、读取页面 HTML 和输入框的值,还能在页面里执行任意 JavaScript。
在 Lambda 上运行有硬性限制吗?有——单次执行不能超过 Lambda 的 5 分钟上限,并发执行数上限是 1000。好消息是,README 说 AWS 免费额度轻松覆盖超过 10 万次测试。
安装之前能不能先试用一下?可以——README 里链接了一个基于浏览器的在线演示平台,不用搭建任何环境就能试用 Chromeless 的 API。
Creator
schickling
Size
1.1 MB
Stars
13.2K
Age
9y
Commits · 90 Days