lucacasonato / deno-puppeteer

A port of puppeteer running on Deno
https://deno.land/x/puppeteer
MIT License
454 stars 44 forks source link

Non try/catchable TimeoutError #84

Open devingfx opened 1 year ago

devingfx commented 1 year ago

Hi !

I found a weird bug : this error, that occurs in a timeout is not catchable with a try/catch clause around puppeteer.launch.

let browser
try {
    browser = await puppeteer.launch({ ...opts })
}
catch(e)
{
    browser = await puppeteer.connect({ ...ws })
}

https://github.com/lucacasonato/deno-puppeteer/blob/45b3162585b98ad8d54abeb56f48ecbb17c614eb/src/deno/BrowserRunner.ts#L163-L165

This occurs while trying to launch a browser / user-data-dir couple a second time, chrome won't open a new instance but instead open a new page on the existing browser instance, and though don't output to stdout the ws endpoint as usual... The try / catch in fact work as expected, and connects to the instance instead in this case, but the sub task (out of scope) launch that failed will crash the process after 30s timeout not connecting... even if it was expicitely used in a try clause...

devingfx commented 1 year ago

I try the other way around:
Try to connect ws 1st and then if fail use launch... This work. But another problem pop up: as I want to open not headless windows with no ui with the commandline argument --app= I need to call puppeteer.launch for that, as nor puppeteer nor CDP are able to open this kind of window.

So I finished to use launch still even when after a connect, what work quite well! I can open several times the same exe/user-dir/window/page without UI, but only for 30s :sob: then still this TimeoutError crashes the process !

devingfx commented 1 year ago

The catched error is from readline:

https://github.com/lucacasonato/deno-puppeteer/blob/45b3162585b98ad8d54abeb56f48ecbb17c614eb/src/deno/BrowserRunner.ts#L168

you may need to try/catch readline (that fail because the executable doesn't output anything while executed a 2nd time with same user-data-dir ) to be able to clearTimeout(timeId) and rethrow ...

devingfx commented 1 year ago

I even tried to augment the timeout, but there is a 24 days limit due to int32, a delay that is not suitable for server side applications that should be up for days...