本文介绍了如何在Docker中运行无头浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用无头浏览器构建Crawler,但是现在我想对我的应用进行docker化,我已经在docker映像中安装了chrome,但是运行脚本时却抛出了错误.

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.

StartChrome.js

StartChrome.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

推荐答案

您可以尝试使用诸如 yukinying/chrome-headless-browser 之类的Docker映像或以下类似映像:"> https://hub.docker.com/r/yukinying/chrome-headless-browser/

You can try with a Docker Image like yukinying/chrome-headless-browser or similar: https://hub.docker.com/r/yukinying/chrome-headless-browser/

根据说明:

这篇关于如何在Docker中运行无头浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:59