@@ -115,50 +115,44 @@ export async function withBrowserApp(
115115}
116116
117117export async function withBrowser ( fn : ( page : Page ) => void | Promise < void > ) {
118- const aborter = new AbortController ( ) ;
118+ const browser = await launch ( {
119+ args : [
120+ "--window-size=1280,7201" ,
121+ ...( ( Deno . env . get ( "CI" ) && Deno . build . os === "linux" )
122+ ? [ "--no-sandbox" ]
123+ : [ ] ) ,
124+ ] ,
125+ headless : ! Deno . args . includes ( "--headful" ) ,
126+ } ) ;
127+ const page = await browser . newPage ( ) ;
128+ // page.setDefaultTimeout(1000000);
119129 try {
120- const browser = await launch ( {
121- args : [
122- "--window-size=1280,7201" ,
123- ...( ( Deno . env . get ( "CI" ) && Deno . build . os === "linux" )
124- ? [ "--no-sandbox" ]
125- : [ ] ) ,
126- ] ,
127- headless : ! Deno . args . includes ( "--headful" ) ,
128- } ) ;
129-
130- const page = await browser . newPage ( ) ;
131- // page.setDefaultTimeout(1000000);
130+ await fn ( page ) ;
131+ } catch ( err ) {
132132 try {
133- await fn ( page ) ;
134- } catch ( err ) {
135- try {
136- const raw = await page . content ( ) ;
137- const doc = parseHtml ( raw ) ;
138- const html = prettyDom ( doc ) ;
139- // deno-lint-ignore no-console
140- console . log ( html ) ;
141- } catch {
142- // Ignore
143- }
144- throw err ;
145- } finally {
146- await page . close ( ) ;
147- await browser . close ( ) ;
133+ const raw = await page . content ( ) ;
134+ const doc = parseHtml ( raw ) ;
135+ const html = prettyDom ( doc ) ;
136+ // deno-lint-ignore no-console
137+ console . log ( html ) ;
138+ } catch {
139+ // Ignore
148140 }
141+ throw err ;
149142 } finally {
150- aborter . abort ( ) ;
143+ await page . close ( ) ;
144+ await browser . close ( ) ;
151145 }
152146}
153147
154148export async function withChildProcessServer (
155149 dir : string ,
156- entry : string ,
150+ task : string ,
157151 fn : ( address : string ) => void | Promise < void > ,
158152) {
159153 const aborter = new AbortController ( ) ;
160154 const cp = await new Deno . Command ( Deno . execPath ( ) , {
161- args : [ "run " , "-A" , entry ] ,
155+ args : [ "task " , task ] ,
162156 stdin : "null" ,
163157 stdout : "piped" ,
164158 stderr : "inherit" ,
0 commit comments