V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
tomiaa
V2EX  ›  程序员

puppeteer 在循环调用的时候经常报错 catch TargetCloseError: Protocol error

  •  
  •   tomiaa · 2024-12-05 22:04:22 +08:00 · 1213 views
    This topic created in 368 days ago, the information mentioned may be changed or developed.

    可能循环个 10 次会遇到一两次,内存也够用 catch TargetCloseError: Protocol error (Emulation.setTouchEmulationEnabled): Session closed. Most likely the page has been closed.

    for (let index = i; index < urls.length; ) {
          let item = urls[index];
    
          const page = await browser.newPage();
          page.setDefaultTimeout(0);  
          page.setDefaultNavigationTimeout(0);
          await page.setViewport({ width: 1080, height: 1024 });
    
          await page.goto(item, {
            waitUntil: "domcontentloaded",
            protocolTimeout: 600000,
          });
          console.log("goto");
    xxxxx...
          }
    
    2 replies    2024-12-07 15:59:18 +08:00
    youngbin0514
        1
    youngbin0514  
       2024-12-06 10:24:29 +08:00
    你这个每次都新建一个页面吧,用完得 close 吧
    tomiaa
        2
    tomiaa  
    OP
       2024-12-07 15:59:18 +08:00 via iPhone
    @youngbin0514 close 也是一样,也试了全局新建了一个 page 循环里面去 goto 跳转页面还是会报错
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3003 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:01 · PVG 21:01 · LAX 05:01 · JFK 08:01
    ♥ Do have faith in what you're doing.