new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Playwright · API reference · all subjects

error handling & exceptions

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Playwright.errors property

Playwright.errors is a property available in JavaScript of type Object that contains error classes. It includes TimeoutError, which is a function/class that represents timeout errors. Playwright methods might throw errors if they are unable to fulfill a request, such as Locator.waitFor failing when the selector doesn't match any nodes during the given timeframe.

TimeoutError handling example JavaScript

try { await page.locator('.foo').waitFor(); } catch (e) { if (e instanceof playwright.errors.TimeoutError) { // Do something if this is a timeout. } }

TimeoutError handling example Python sync

try: page.wait_for_selector(".foo") except TimeoutError as e: pass # do something if this is a timeout.

Page.clearPageErrors async method

Page.clearPageErrors clears all stored page errors from this page. Subsequent calls to Page.pageErrors will only return errors thrown after the clear. Available since v1.59.

Page.pageErrors return type and filter option

Page.pageErrors returns Array<Error> in JavaScript and Python, or Array<string> in C# and Java. It returns up to (currently) 200 last page errors from this page. Takes optional filter option with values 'since-navigation' (default - returns only errors after last committed main-frame navigation) or 'all' (returns all stored errors). Available since v1.56.

Give your agent this brain