Feature request: "Soft" timeout when using WaitFor<x>
See original GitHub issueWhile discussing another issue with @kblok, I stumbled upon another small hiccup which lead me to think about this feature request.
The initial problem is that I had timeout errors while trying to generate a pdf. I finally found the culprit, I was using page.WaitForSelector
in which I specified a selector that is was always present on page depending on some conditions.
To make a long explanation “relatively shorter”:
- I am generating a report in which I do generate trending graphics, but only when enough data is present to make it useful.
- As this can be a relatively long process (couple seconds), I had to find a way to wait until the graphics are generated before doing the pdf conversion, otherwise I would be left with partial reports.
- I decided to use the
page.WaitForSelector
which is waiting on an element with a css class that is given to it once all graphics have completed their initialization. - The problem was that if not enough data was provided, I was skipping the graphics initialization (and consequently the css flag was never added to the element, resulting in the timeout)
I would want to know if there is a way to use WaitForSelector
, but instead of having a hard timeout in which an exception is thrown, it would be really nice if we could have an option to set a “soft timeout” which would simply block the generation process while waiting for the selector and after the specified timeout, simply go on and perform the conversion even if the condition was not respected.
I think that could add a certain flexibility to the usage of the page.WaitFor<x>
for cases when the desired outcome would be, simply said “Wait until condition is respected, otherwise simply go on and do the conversion/perform the remaining script steps”, which is not possible at the moment with Playwright from my understanding.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
@arjunattam we talked with @lvmajor about that here https://github.com/microsoft/playwright-sharp/issues/942#issuecomment-708651438 .
That’s a possible solution. The thing is that an exception in .NET is “expensive”. There is a good practice that says that you shouldn’t use try-catch to control the flow.
I’m wondering if this could be a feature in PW, or something with can do on PW# to avoid the exceptions…
Lol you beat me to it a couple seconds ahah