1- import { Browser , launch , Page } from "jsr:@astral/astral" ;
1+ import { Browser , ConsoleEvent , launch , Page } from "jsr:@astral/astral" ;
22import { Manifest } from "./manifest.ts" ;
33import { tsToJs , wait } from "./utils.ts" ;
44import { TestResult } from "./interface.ts" ;
5+ import { extractAstralConfig } from "./config.ts" ;
56
6- export class BrowserController {
7+ export class BrowserController extends EventTarget {
78 private manifest : Manifest ;
89 private page : Page | null ;
910 private browser : Browser | null ;
1011
1112 constructor ( manifest : Manifest ) {
13+ super ( ) ;
1214 this . manifest = manifest ;
1315 this . browser = null ;
1416 this . page = null ;
@@ -23,8 +25,18 @@ export class BrowserController {
2325 if ( this . page ) {
2426 await this . page . goto ( testUrl ) ;
2527 } else {
26- this . browser = await launch ( config . astral ?? { } ) ;
28+ this . browser = await launch ( extractAstralConfig ( config ) ) ;
2729 this . page = await this . browser . newPage ( testUrl ) ;
30+ this . page . addEventListener ( "console" , ( e ) => {
31+ // Not sure why this event needs reconstructed in order
32+ // to re-fire, rather than just passing it into `dispatchEvent`.
33+ this . dispatchEvent (
34+ new ConsoleEvent ( {
35+ type : e . detail . type ,
36+ text : e . detail . text ,
37+ } ) ,
38+ ) ;
39+ } ) ;
2840 }
2941 await this . waitUntilReady ( ) ;
3042 }
0 commit comments