我试图弄清楚如何在 docker 容器中运行 headless Chrome。然后我找到了this .
但是现在我不知道如何在那个容器中运行我的测试。
谁能给我一个大致的方向,我应该在哪里挖掘,我试着浏览 Pupeeteer的文档,但找不到任何东西。
也许在野外有一个最小的例子,我可以使用 Karma 或其他任何东西在容器中运行测试并记录结果。
请注意,尽管我想在容器之外编译/捆绑 javascript,并使用它来执行其中的已编译/捆绑测试。
也许稍后我想使用相同的方法来运行我的验收测试,但这次是通过在外部运行 Web 服务器,可能在一个单独的容器中。
我的最终目标是能够运行大量用 Clojurescript 编写的测试,但我认为虽然还没有人做过类似的事情。也许有人有。
最佳答案
我想我已经草拟了一个游戏计划:
docker run -it --rm -p=0.0.0.0:9222:9222 --name=chrome-headless \
-v /tmp/chromedata/:/data alpeware/chrome-headless-trunk
我们需要找到该选项卡的 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
});
这一切都很好,现在我要用这些砖 block “盖房子”
关于google-chrome - Puppeteer 不是容器中的 headless Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45930961/