SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
333 stars 105 forks source link

TimeoutError: waiting for target failed: timeout 30000ms exceeded #110

Open flyfhj opened 1 year ago

flyfhj commented 1 year ago

Hello, I am running the following script on a linux OS:

const { launch, getStream } = require("puppeteer-stream");
const fs = require("fs");
const file = fs.createWriteStream(__dirname + "/test.webm");
async function test() {
    const browser = await launch({
        args: ['--no-sandbox'],
        allowIncognito: true,
        executablePath:'/web/download/node_modules/puppeteer/.local-chromium/linux-1056772/chrome-linux/chrome',
        headless: false,
        defaultViewport: {
            width: 1280,
            height: 1024
        },
        ignoreDefaultArgs: ["--disable-extensions", "--mute-audio"]
    });

    const page = await browser.newPage();
    await page.goto("https://www.bilibili.com/video/BV1kL411h7D5/");
    console.log("beginning......");
    const stream = await getStream(page, { audio: true, video: true });
    console.log("recording......");
    stream.pipe(file);
}
test();

But it always throws the following exception: timeout 30000ms exceeded

In order to be able to locate the problem, I added a log to the waitForTarget method in node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js

CODE:

 async waitForTarget(predicate, options = {}) {
 ...
 try {
     this.targets().forEach(check);
     if (!timeout) {
         return await targetPromise;
     }
     return await (0, util_js_1.waitWithTimeout)(targetPromise, 'target', timeout);
 }
 ...
 async function check(target) {
     console.log("<======check======>" + target.type() + ":" + target.url());
     if ((await predicate(target)) && !targetPromise.resolved()) {
         targetPromise.resolve(target);
     }
 }

The exception information is as follows:

<======check======>browser:
<======check======>page:about:blank
beginning......
<======check======>browser:
<======check======>page:about:blank
<======check======>service_worker:chrome-extension://jjndjgheafjngoipoacpjgeicjeomjli/background.js
<======check======>page:about:blank
<======check======>service_worker:chrome-extension://jjndjgheafjngoipoacpjgeicjeomjli/background.js
<======check======>service_worker:chrome-extension://jjndjgheafjngoipoacpjgeicjeomjli/background.js
/web/download/node_modules/puppeteer-core/lib/cjs/puppeteer/common/util.js:292
    const timeoutError = new Errors_js_1.TimeoutError(`waiting for ${taskName} failed: timeout ${timeout}ms exceeded`);
                         ^
TimeoutError: waiting for target failed: timeout 30000ms exceeded
    at waitWithTimeout (/web/download/node_modules/puppeteer-core/lib/cjs/puppeteer/common/util.js:292:26)
    at CDPBrowser.waitForTarget (/web/download/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:342:56)
    at /web/download/node_modules/puppeteer-stream/dist/PuppeteerStream.js:107:47
    at Generator.next (<anonymous>)
    at /web/download/node_modules/puppeteer-stream/dist/PuppeteerStream.js:31:71
    at new Promise (<anonymous>)
    at __awaiter (/web/download/node_modules/puppeteer-stream/dist/PuppeteerStream.js:27:12)
    at getExtensionPage (/web/download/node_modules/puppeteer-stream/dist/PuppeteerStream.js:106:12)
    at /web/download/node_modules/puppeteer-stream/dist/PuppeteerStream.js:132:33
    at Generator.next (<anonymous>)

Version:

node:v16.14.0 npm:8.3.1 os:Linux version 3.10.0-1160.66.1.el7.x86_64 puppeteer:19.2.2 puppeteer-stream:3.0.3 chrome:linux-1056772

Hope to get your help,Thanks!

nivhsay commented 1 year ago

Try giving the headless argument to your chrome/chromium. Usually --headless=new on newer versions.

flyfhj commented 1 year ago

Try giving the headless argument to your chrome/chromium. Usually --headless=new on newer versions.

Hi,I use the following parameters:

await launch({
   ...
   headless:'new',
   ...

But it still throws the same error.

nivhsay commented 1 year ago

The puppeteer-stream code overrides the headless launch option here

I believe the chrome extension needs the browser to launch with a "GUI" it to record the page. So, setting it on the args works as it uses a virtual GUI with the Ozone platform, and this is not overridden by puppeteer-stream.

await launch({
   ...
  args: [
     ...
      '--headless=new',
     ...
    ],
   ...
pantajoe commented 9 months ago

I have the same problem and also receive the error TimeoutError: waiting for target failed on browser startup. @flyfhj Did you manage to solve that issue? @SamuelScheit Any insights into what's causing the issue?

jcuna commented 8 months ago

Having the same issue. Any updates?

Takeno commented 8 months ago

Having the same issue. Any updates? @jcuna

I am able to run it headless with this configuration:

  const browser = await launch({
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    defaultViewport: {
      width: 1920,
      height: 1080,
    },
    args: [
      '--no-sandbox',
      '--headless=new',
    ],
  });