Puppeteer 错误:启动浏览器进程失败!、pthread_create、ERROR:platform_thread_posix.cc(135)、资源暂时不可用(11)

时间:2021-06-07 14:27:40

标签: javascript puppeteer ubuntu-server

我有这个 Puppeteer 文件,我试图在 Ubuntu 服务器上运行:

var puppeteer = require('puppeteer')

const browser = await puppeteer.launch({
    'headless' : true,
    "executablePath": "/usr/bin/chromium-browser", 
    "args": [
        '--disable-setuid-sandbox',
            '--no-sandbox',
            '--disable-gpu',
            //'--no-first-run' 
    ]
})
const page = await browser.newPage()

它在我的计算机上运行良好,但是当我尝试在我的服务器上运行它时,出现以下错误。我已经阅读了很多关于这个主题的帖子,并查看了 Github 上的故障排除文件,但对我来说没有任何作用。

如何通过在 Ubuntu 服务器上运行 Puppeteer 来解决此问题?我使用的是最新版本 Ubuntu 18.04.5 LTS。

root@h2922648:~/Test# node test.js
[0620/162429.725764:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is swiftshader

DevTools listening on ws://127.0.0.1:36132/devtools/browser/6c0ea0f9-d0a8-4fb8-85b9-61e9a2759b67
Start
[0620/162430.186785:ERROR:platform_thread_posix.cc(148)] pthread_create: Die Ressource ist zur Zeit nicht verfügbar (11)
[0620/162430.187119:FATAL:thread_pool_impl.cc(178)] Check failed: service_thread_.StartWithOptions(std::move(service_thread_options)).
#0 0x55670c3baaa9 base::debug::CollectStackTrace()
#1 0x55670c3260e3 base::debug::StackTrace::StackTrace()
#2 0x55670c337730 logging::LogMessage::~LogMessage()
#3 0x55670c33827e logging::LogMessage::~LogMessage()
#4 0x55670c394f80 base::internal::ThreadPoolImpl::Start()
#5 0x55670f84321f content::ChildProcess::ChildProcess()
#6 0x556711078b03 content::RenderProcess::RenderProcess()
#7 0x556711078423 content::RenderProcessImpl::RenderProcessImpl()
#8 0x556711078abb content::RenderProcessImpl::Create()
#9 0x5567117ddce3 content::RendererMain()
#10 0x55670c2c267c content::RunZygote()
#11 0x55670c2c390e content::ContentMainRunnerImpl::Run()
#12 0x55670c2c0f7d content::RunContentProcess()
#13 0x55670c2c191d content::ContentMain()
#14 0x55670c3203b6 headless::(anonymous namespace)::RunContentMain()
#15 0x55670c32011e headless::RunChildProcessIfNeeded()
#16 0x55670c31e9f5 headless::HeadlessShellMain()
#17 0x556709204264 ChromeMain
#18 0x7f3654e01bf7 __libc_start_main
#19 0x5567092040aa _start

Received signal 6
#0 0x55670c3baaa9 base::debug::CollectStackTrace()
#1 0x55670c3260e3 base::debug::StackTrace::StackTrace()
#2 0x55670c3ba5d1 base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x7f365986c980 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1297f)
#4 0x7f3654e1efb7 gsignal
#5 0x7f3654e20921 abort
#6 0x55670c3b9895 base::debug::BreakDebugger()
#7 0x55670c337b57 logging::LogMessage::~LogMessage()
#8 0x55670c33827e logging::LogMessage::~LogMessage()
#9 0x55670c394f80 base::internal::ThreadPoolImpl::Start()
#10 0x55670f84321f content::ChildProcess::ChildProcess()
#11 0x556711078b03 content::RenderProcess::RenderProcess()
#12 0x556711078423 content::RenderProcessImpl::RenderProcessImpl()
#13 0x556711078abb content::RenderProcessImpl::Create()
#14 0x5567117ddce3 content::RendererMain()
#15 0x55670c2c267c content::RunZygote()
#16 0x55670c2c390e content::ContentMainRunnerImpl::Run()
#17 0x55670c2c0f7d content::RunContentProcess()
#18 0x55670c2c191d content::ContentMain()
#19 0x55670c3203b6 headless::(anonymous namespace)::RunContentMain()
#20 0x55670c32011e headless::RunChildProcessIfNeeded()
#21 0x55670c31e9f5 headless::HeadlessShellMain()
#22 0x556709204264 ChromeMain
#23 0x7f3654e01bf7 __libc_start_main
#24 0x5567092040aa _start
  r8: 0000000000000000  r9: 00007fffaf96c090 r10: 0000000000000008 r11: 0000000000000246
 r12: 00000fa200488640 r13: 00007fffaf96c2f0 r14: 00000fa200488650 r15: aaaaaaaaaaaaaaaa
  di: 0000000000000002  si: 00007fffaf96c090  bp: 00007fffaf96c2e0  bx: 00007fffaf96cb20
  dx: 0000000000000000  ax: 0000000000000000  cx: ffffffffffffffff  sp: 00007fffaf96c090
  ip: 00007f3654e1efb7 efl: 0000000000000246 cgf: 0000000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]

1 个答案:

答案 0 :(得分:0)

所以我在这里发布一个工作代码。

在评论中,我提到了您的代码中缺少什么以及我们为什么需要它。

确保您的 ubuntu 机器上已经安装了以下内容:

apt-get install -y curl google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1

它很卡,因为我们必须在所有操作之后关闭浏览器。

我也添加了 dumpio,它将启用调试模式。

var puppeteer = require('puppeteer-core')

var adresse = "https://www.google.de/"

async function test() {
try {
    const browser = await puppeteer.launch({
        "dumpio": true,
        "headless": true,
        "executablePath": '/usr/bin/chromium-browser',
        "args": [
            '--disable-setuid-sandbox',
            '--no-sandbox',
            '--disable-gpu',
        ]
    })
    console.log("Start");
    const page = await browser.newPage();
    console.log("1");
    await page.goto(adresse, { waitUntil: ['load', 'networkidle0'] }); // WAIT for the page load finish. Provide wait options, you can read moe about it in documentation.
    console.log("2");
    console.log(page);
    await page.screenshot({path: 'buddy-screenshot.png'}); // WHAT you wanted to do with the page. You can take Screenshot or generate pdf.

    await page.close(); // After job done close the page
    await browser.close(); // IMPORTANT: you have to shutdown the browser in order to proceed with the results.
        
    } catch (error) {
       console.log(error)
    }
}

await test(); // For safe side wait for it.