Starter Kit for running Headless-Chrome by Puppeteer on AWS Lambda.
It can use alone and also supported Serverless Framework.
This is simple and don't need IAM role but you have to deploy package by yourself. Don't worry, even if you will become to use Serverless in the future, what you should do for migration is little.
$ git clone -o starter-kit https://github.com/sambaiz/puppeteer-lambda-starter-kit.git your_project_name
Serverless Framework can manage settings with CloudFormation and deploy.
$ serverless install --url https://github.com/sambaiz/puppeteer-lambda-starter-kit --name your_project_name
By executing SLOWMO_MS=250 npm run local
, you can check the operation while actually viewing the chrome (non-headless, slowmo).
Lambda's memory needs to be set to at least 384 MB, but the more memory, the better the performance of any operations.
512MB -> goto(youtube): 6.481s
1536MB -> goto(youtube): 2.154s
If you use alone, run npm run package
, and deploy the package.zip.
If you use with Serverless, run serverless deploy
(this runs npm run package
when packaging).
Due to the large size of Chrome, it may exceed the Lambda package size limit (50MB) depending on the other module to include.In that case, put Chrome in S3 and download it at container startup so startup time will be longer.
Run npm run package-nochrome
, deploy the package.zip, and set following env valiables on Lambda.
CHROME_BUCKET
(required): S3 bucket where Chrome is putCHROME_KEY
(optional): S3 key. default: headless_shell.tar.gz
This kit includes Chrome built by myself because official build Chrome installed by Puppeteer has problems about running on Lambda (missing shared library etc.).
If you want to use latest chrome, run chrome/buildChrome.sh on EC2 having at least 16GB memory and 30GB volume.See also serverless-chrome.Once you build it, link to headless_shell.tar.gz
in chrome
dir.
Lambda上でPuppeteer/Headless Chromeを動かすStarter Kitを作った - sambaiz-net
Puppeteer 是一个控制 headless Chrome 的 Node.js API 。它是一个 Node.js 库,通过 DevTools 协议提供了一个高级的 API 来控制 headless Chrome。它还可以配置为使用完整的(非 headless)Chrome。 在浏览器中手动完成的大多数事情都可以通过使用 Puppeteer 完成,下面是一些入门的例子: 生成屏幕截图和 PDF
自 v1.7.0 以来的每个版本我们都发布了两个包: puppeteer puppeteer-core puppeteer 是浏览器自动化的 产品。安装后,它会下载一个版本的 Chromium,然后使用puppeteer-core 驱动工作。作为最终用户产品,puppeteer 支持一堆方便的 PUPPETEER_* env 变量来调整行为。 puppeteer-core 是一个 库 来帮助驱动任
Puppeteer 模块提供了一种启动 Chromium 实例的方法。 下面就是使用 Puppeteer 进行自动化的一个典型示例: const puppeteer = require('puppeteer'); puppeteer.launch().then(async browser => { const page = await browser.newPage(); await p
jest-puppeteer 允许你使用 Jest & Puppeteer 运行测试。 # for jest 22~23npm install --save-dev jest-puppeteer@3.9.0 puppeteer jest# for jest 24+npm install --save-dev jest-puppeteer puppeteer jest 需要 Jest v22 及以上
Puppeteer Sharp 是官方 Node.JS Puppeteer API 的 .NET 端口。 相关链接 API 文档 StackOverflow Issues 用法 截屏 using var browserFetcher = new BrowserFetcher();await browserFetcher.DownloadAsync();await using var browser
Puppeteer 是用 JavaScript 测试 Web 应用程序的框架。