@@ -21,6 +21,7 @@ import {
2121 registerForExitCleanup ,
2222 unregisterForExitCleanup ,
2323} from "../process.ts" ;
24+ import { assert } from "testing/asserts" ;
2425
2526async function waitForServer ( port : number , timeout = 3000 ) {
2627 const interval = 50 ;
@@ -87,8 +88,7 @@ export async function criClient(appPath?: string, port?: number) {
8788 // Allow to adapt the headless mode depending on the Chrome version
8889 const headlessMode = getenv ( "QUARTO_CHROMIUM_HEADLESS_MODE" , "none" ) ;
8990
90- const cmd = [
91- app ,
91+ const args = [
9292 // TODO: Chrome v128 changed the default from --headless=old to --headless=new
9393 // in 2024-08. Old headless mode was effectively a separate browser render,
9494 // and while more performant did not share the same browser implementation as
@@ -106,19 +106,27 @@ export async function criClient(appPath?: string, port?: number) {
106106 "--renderer-process-limit=1" ,
107107 `--remote-debugging-port=${ port } ` ,
108108 ] ;
109- const browser = Deno . run ( { cmd, stdout : "piped" , stderr : "piped" } ) ;
109+ const browser = new Deno . Command ( app , {
110+ args,
111+ stdout : "piped" ,
112+ stderr : "piped" ,
113+ } ) ;
110114
115+ const cmd = browser . spawn ( ) ;
111116 // Register for cleanup inside exitWithCleanup() in case something goes wrong
112- const thisProcessId = registerForExitCleanup ( browser ) ;
117+ const thisProcessId = registerForExitCleanup ( cmd ) ;
113118
114119 if ( ! ( await waitForServer ( port as number ) ) ) {
115120 let msg = "Couldn't find open server." ;
116121 // Printing more error information if chrome process errored
117- if ( ! ( await browser . status ( ) ) . success ) {
122+ if ( ! ( await cmd . status ) . success ) {
118123 debug ( `[CHROMIUM path] : ${ app } ` ) ;
119124 debug ( `[CHROMIUM cmd] : ${ cmd } ` ) ;
120- const rawError = await browser . stderrOutput ( ) ;
121- const errorString = new TextDecoder ( ) . decode ( rawError ) ;
125+ const rawError = await cmd . stderr ;
126+ const reader = rawError . getReader ( ) ;
127+ const readerResult = await reader . read ( ) ;
128+ assert ( readerResult . done ) ;
129+ const errorString = new TextDecoder ( ) . decode ( readerResult . value ! ) ;
122130 msg = msg + "\n" + `Chrome process error: ${ errorString } ` ;
123131 }
124132
@@ -135,8 +143,7 @@ export async function criClient(appPath?: string, port?: number) {
135143 // We have a bug where `client.close()` doesn't return properly and we don't go below
136144 // meaning the `browser` process is not killed here, and it will be handled in exitWithCleanup().
137145
138- browser . kill ( ) ; // Chromium headless won't terminate on its own, so we need to send kill signal
139- browser . close ( ) ; // Closing the browser Deno process
146+ cmd . kill ( ) ; // Chromium headless won't terminate on its own, so we need to send kill signal
140147 unregisterForExitCleanup ( thisProcessId ) ; // All went well so not need to cleanup on quarto exit
141148 } ,
142149
0 commit comments