From 39ce35e15419dd9bcdc4705b84a41c8cd5cb1a83 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 24 Jun 2020 15:12:17 -0700 Subject: [PATCH] fix(errors): strict error handling around element operations (#2567) - Gave all possible dom errors distinct names, and throw them on the node side. - Separated errors into FatalDOMError and RetargetableDOMError. Fatal errors are unrecoverable. Retargetable errors could be resolved by requerying the selector. - This exposed a number of unhandled 'notconnected' cases. - Added helper functions to handle errors and ensure TypeScript catches unhandled ones. --- docs/api.md | 21 +-- src/chromium/crPage.ts | 8 +- src/common/domErrors.ts | 27 ++++ src/dom.ts | 239 +++++++++++++++------------ src/firefox/ffPage.ts | 6 +- src/frames.ts | 8 +- src/injected/injectedScript.ts | 285 ++++++++++++++++----------------- src/page.ts | 2 +- src/selectors.ts | 19 ++- src/types.ts | 4 +- src/webkit/wkPage.ts | 6 +- test/page.spec.js | 10 +- 12 files changed, 345 insertions(+), 290 deletions(-) create mode 100644 src/common/domErrors.ts diff --git a/docs/api.md b/docs/api.md index df5791d871..5067a33eba 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1302,10 +1302,11 @@ const fs = require('fs'); - `options` <[Object]> - `noWaitAfter` <[boolean]> Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`. - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. -- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully filled. The promise will be rejected if there is no element matching `selector`. +- returns: <[Promise]> -This method focuses the element and triggers an `input` event after filling. -If there's no text ``, `