playwright-java icon indicating copy to clipboard operation
playwright-java copied to clipboard

[Feature]: Add specific 'getter' to PlaywrightException for the error message

Open jgangemi opened this issue 5 months ago • 0 comments

🚀 Feature Request

It would be great if the specific message in the Error object could be parsed out and available via a specific getter method on the PlaywrightException class.

Example

In the following example

com.microsoft.playwright.PlaywrightException: Error {
  message='NS_ERROR_UNKNOWN_HOST
  name='Error
  stack='Error: NS_ERROR_UNKNOWN_HOST
    at FrameManager.frameAbortedNavigation (/private/var/folders/6z/49sfh8n104l0594pymhlqfzh0000gn/T/playwright-java-8205705741105414397/package/lib/server/frames.js:221:14)
    at FrameManager.requestFailed (/private/var/folders/6z/49sfh8n104l0594pymhlqfzh0000gn/T/playwright-java-8205705741105414397/package/lib/server/frames.js:280:12)
    at FFNetworkManager._onRequestFailed (/private/var/folders/6z/49sfh8n104l0594pymhlqfzh0000gn/T/playwright-java-8205705741105414397/package/lib/server/firefox/ffNetworkManager.js:138:30)
    at FFSession.emit (node:events:518:28)
    at /private/var/folders/6z/49sfh8n104l0594pymhlqfzh0000gn/T/playwright-java-8205705741105414397/package/lib/server/firefox/ffConnection.js:154:41
}
Call log:
-   - navigating to "http://some-domain-that-doesnt-exist.com/", waiting until "load"

I would just like to catch the exception and call something like e.getErrorCode() and have NS_ERROR_UNKNOWN_HOST returned instead of having to write a regexp to parse it out.

Motivation

I am using Playwright to take screenshots of websites that can be quickly scanned to tell if someone is squatting the domain. If the page can't be navigated to, I can provide a more human friendly reason why based on said message/error code.

jgangemi avatar Jun 12 '25 00:06 jgangemi