Pupeeteer在一个容器中无头的Chrome

我试图找出如何在Docker容器中运行无头的Chrome。 然后我find了这个 。 但现在我不知道如何在该容器中运行我的testing。

有人能给我一个大致的方向,我应该在哪里挖掘,我尝试翻看Pupeeteer的文档,但找不到任何东西。 也许在野外有一个很小的例子,我可以使用Karma或其他方法在容器中运行testing并logging结果。

请注意,虽然我想在容器外编译/捆绑javascript,并且只是为了在其中执行编译/捆绑testing。

也许以后我想用相同的方法来运行我的验收testing,但这次通过运行一个外部的web服务器,可能在一个单独的容器。

我的最终目标是能够运行一些用Clojurescript编写的testing,我不认为有人做过类似的事情。 也许有人有。

我想我已经勾勒出一个游戏计划:

  • 首先需要运行容器:

    docker run -it --rm -p=0.0.0.0:9222:9222 --name=chrome-headless \ -v /tmp/chromedata/:/data alpeware/chrome-headless-trunk 
  • 现在,当Chrome运行时,您可以打开http:// localhost:9222进行检查 。 你应该看到那里有一个标签。 我们需要find该选项卡的websocketUrl,运行:

     curl http://localhost:9222/json # should get you something like this: [{"description": "", "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/2f428ea1-7229-484c-b7c7-57ef2f098ffe", "id": "2f428ea1-7229-484c-b7c7-57ef2f098ffe", "title": "Google", "type": "page", "url": "https://www.google.com/", "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/2f428ea1-7229-484c-b7c7-57ef2f098ffe"}] 
  • 现在你可以使用木偶连接并做一些疯狂的事情:

     const puppeteer = require('puppeteer'); puppeteer.connect({ browserWSEndpoint: "ws://localhost:9222/devtools/page/2f428ea1-7229-484c-b7c7-57ef2f098ffe" }).then (async browser => { const page = await browser.newPage(); await page.goto('https://www.google.com'); ;; you just opened another tab }); 

这一切都很好,现在所有这些砖块我都要“盖房子”