Puppeteer 在 .newPage() 处被阻止

Puppeteer blocked at .newPage()

我想用 Puppeteer 生成 PDF。

我的环境开发

我尝试了网上的很多教程来做到这一点。 但是代码在 browser.newPage()

上被屏蔽了
const browser = await puppeteer.launch();
console.log(await browser.version()); //HeadlessChrome/90.0.4427.0 
const page = await browser.newPage(); //after it does nothing

这里是调试(最后六行):

  puppeteer:protocol:RECV ◀ {"id":4,"result":{"sessionId":"B3D2567E07203D4A096A495710466966"}} +0ms
  puppeteer:protocol:SEND ► {"sessionId":"B3D2567E07203D4A096A495710466966","method":"Page.enable","params":{},"id":5} +1ms
  puppeteer:protocol:SEND ► {"sessionId":"B3D2567E07203D4A096A495710466966","method":"Page.getFrameTree","params":{},"id":6} +1ms
  puppeteer:protocol:SEND ► {"sessionId":"B3D2567E07203D4A096A495710466966","method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":false,"flatten":true},"id
":7} +0ms
  puppeteer:protocol:SEND ► {"sessionId":"B3D2567E07203D4A096A495710466966","method":"Performance.enable","params":{},"id":8} +0ms
  puppeteer:protocol:SEND ► {"sessionId":"B3D2567E07203D4A096A495710466966","method":"Log.enable","params":{},"id":9} +0ms

谢谢,

我已经解决了我的问题:

使用dumpio: true显示Puppeteer的日志。 之后,我发现 libX11-xcb.so.1 的错误并禁用了 gpu。

  browser = await chromium.launch({
      args: ["--disable-gpu"]
    });

https://github.com/puppeteer/puppeteer/issues/1543#issuecomment-349642975 https://github.com/microsoft/playwright/issues/4761#issue-770834723