V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
silvernoo
V2EX  ›  Node.js

puppeteer 控制 chromium 经常卡死是什么原因

  •  
  •   silvernoo · Oct 13, 2019 · 5998 views
    This topic created in 2391 days ago, the information mentioned may be changed or developed.

    https://gist.github.com/silvernoo/b998086fd2b933d2dcf70bee7460559a

    十几次循环后必然会卡死,没有任何日志。es 代码不太会写,自己找原因希望渺茫,dalao 帮我看看是怎么回事。

    Supplement 1  ·  Oct 13, 2019

    click替换为就好了,原因不明

            const element = await page.$('[href="#download-license-container"]');
            await element.click();
            await page.waitFor(500);
            const element2 = await page.$('[class="button button-submit"]');
            await element2.click();
    
    1 replies    2019-12-06 08:00:47 +08:00
    guoyongyi11
        1
    guoyongyi11  
       Dec 6, 2019
    我当时使用 puppeteer 碰到如下几种问题会造成 hang 的。

    1. 截图 hang
    界面上没有 body 元素。你可以 goto 界面后,再把 body 元素取出来看一看。

    2. 因为 page crash 而 hang
    程序一旦意外 crash 后,后面执行 page 相关的代码就会被 hang 住,现在的解决办法就是在 page.on('error') 里面把 browser.close 掉,使后面的代码报错,从而被 catch 住,在 catch 里面再做进一步处理。

    3. puppeteer 在跑并行的时候,如果使用 Promise.all ,很容易被其中一个异步方法 hang 住,造成整个进程都 hang 住
    解决方法就是创建并行函数,但不要使用 Promise.all
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   887 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 19:28 · PVG 03:28 · LAX 12:28 · JFK 15:28
    ♥ Do have faith in what you're doing.