55 BrowserError ,
66 BrowserErrorCode ,
77} from './types.js' ;
8+ import { errorToString } from '../../utils/errorToString.js' ;
89
910export class PageController {
1011 constructor ( private page : Page ) { }
@@ -27,13 +28,14 @@ export class PageController {
2728 }
2829 }
2930
30- private validateSelector ( selector : string , type : SelectorType ) : void {
31+ private validateSelector ( selector : string , _type : SelectorType ) : void {
3132 if ( ! selector ) {
3233 throw new BrowserError (
3334 'Invalid selector: empty string' ,
3435 BrowserErrorCode . SELECTOR_INVALID ,
3536 ) ;
3637 }
38+ // TODO: Add more validation
3739 }
3840
3941 async waitForSelector (
@@ -51,7 +53,7 @@ export class PageController {
5153 } ) ;
5254 } catch ( error ) {
5355 throw new BrowserError (
54- `Failed to find element: ${ error } ` ,
56+ `Failed to find element: ${ errorToString ( error ) } ` ,
5557 BrowserErrorCode . ELEMENT_NOT_FOUND ,
5658 error ,
5759 ) ;
@@ -67,7 +69,7 @@ export class PageController {
6769 await locator . click ( { timeout : options . timeout } ) ;
6870 } catch ( error ) {
6971 throw new BrowserError (
70- `Failed to click element: ${ error } ` ,
72+ `Failed to click element: ${ errorToString ( error ) } ` ,
7173 BrowserErrorCode . SELECTOR_ERROR ,
7274 error ,
7375 ) ;
@@ -87,7 +89,7 @@ export class PageController {
8789 await locator . fill ( text , { timeout : options . timeout } ) ;
8890 } catch ( error ) {
8991 throw new BrowserError (
90- `Failed to type text: ${ error } ` ,
92+ `Failed to type text: ${ errorToString ( error ) } ` ,
9193 BrowserErrorCode . SELECTOR_ERROR ,
9294 error ,
9395 ) ;
@@ -106,7 +108,7 @@ export class PageController {
106108 return ( await locator . textContent ( ) ) || '' ;
107109 } catch ( error ) {
108110 throw new BrowserError (
109- `Failed to get text: ${ error } ` ,
111+ `Failed to get text: ${ errorToString ( error ) } ` ,
110112 BrowserErrorCode . SELECTOR_ERROR ,
111113 error ,
112114 ) ;
0 commit comments