简体   繁体   English

如何在docker中运行无头浏览器?

[英]How to run headless browser inside docker?

I am building a Crawler with headless browser But right now I want to dockerize my app I've installed chrome in my docker image But it throw me an error when run the script.我正在构建一个带有无头浏览器的 Crawler 但是现在我想对我的应用程序进行 dockerize 我已经在我的 docker 镜像中安装了 chrome 但是它在运行脚本时抛出了一个错误。

StartChrome.js启动Chrome.js

const chromeLauncher = require('chrome-launcher');

chromeLauncher.launch({
    port: 9222,
    chromeFlags: ['--headless','--proxy-server=54.171.181.204:8888','--disable-web-security','--disable-gpu']
}).then(chrome => {
    console.log(`Chrome debugging port running on ${chrome.port}`);
});

Err错误

(node:415) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 127.0.0.1:9222
(node:415) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

And when I run it in command line it throws me an error like this当我在命令行中运行它时,它会抛出这样的错误

Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
Trace/breakpoint trap

You can try with a Docker Image like yukinying/chrome-headless-browser or similar: https://hub.docker.com/r/yukinying/chrome-headless-browser/您可以尝试使用像yukinying/chrome-headless-browser或类似的 Docker 图像: https : //hub.docker.com/r/yukinying/chrome-headless-browser/

From the description:从描述来看:

This docker image contain the Linux Dev channel Chromium ( https://www.chromium.org/getting-involved/dev-channel ), with the required dependencies and the command line arguments running headless mode.此 docker 映像包含 Linux Dev 频道 Chromium ( https://www.chromium.org/getting-involved/dev-channel ),以及所需的依赖项和运行无头模式的命令行参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在无边框浏览器中的边界框内获取元素 - How to get elements in headless browser inside a bounding box 用量角器运行什么是好的无头浏览器? - What is a good headless browser to run with protractor? 如何在 Docker 容器内运行 javascript 客户端? - How to run a javascript client inside a Docker container? 如何在seleniumwebdriver和chromedriver中使用无头浏览器 - How to use headless browser with seleniumwebdriver and chromedriver 如何使用无头浏览器自动进行一些Web交互? - How to automate some web interaction with a headless browser? 如何使用无头浏览器获取特定的GET请求? - How to get a specific GET Request with a headless browser? 如何运行谷歌浏览器无头木偶代码 - How to run Google Chrome Headless Puppeteer code 如何使用 apify sdk 使 puppeteer 无头运行? - How to make puppeteer run headless with the apify sdk? 如何在浏览器中运行隔离的 Node.js 环境? - How to run an isolated Node.js environment inside browser? 如何在浏览器中安全地运行用户提供的 Javascript 代码? - How to safely run user-supplied Javascript code inside the browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM