【问题标题】:Puppeteer Error: Failed to launch the browser process!, pthread_create, ERROR:platform_thread_posix.cc(135), resource temporarily unavailable (11)Puppeteer 错误:无法启动浏览器进程!,pthread_create,错误:platform_thread_posix.cc(135),资源暂时不可用 (11)
【发布时间】:2021-06-07 14:27:40
【问题描述】:

我想在 Ubuntu 服务器上运行这个 Puppeteer 文件:

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]

【问题讨论】:

  • 你在服务器上安装了google chromium-browser吗?
  • 是的,如果我尝试在没有 pupeteer 的情况下打开它(“chromium-browser --no-sandbox --headless”),我会得到同样的错误。
  • 你在服务器上做过吗,我的意思是安装浏览器。 apt-get install google-chrome-stable 因为我正在运行它 --headless 及其工作。
  • 现在它有点工作,但它只是在尝试创建页面时冻结
  • 本不要使用答案来交流我们的解决方案,否则,您将被评分。我们将在 cmets 中进行交流。再看一下我的代码,试试看生成的图片

标签: javascript puppeteer ubuntu-server


【解决方案1】:

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

在 cmets 中,我提到了您的代码中缺少的内容以及我们需要它的原因。

确保您的 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.

【讨论】:

  • 好的,我已经编辑了我的问题。在那里你可以从你的代码中看到我的控制台输出。
  • 我已经重新安装了我的服务器和 puppeteer 的所有依赖项。在我的问题中,您可以看到我得到的“新错误”
猜你喜欢
  • 2020-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-11
  • 1970-01-01
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多