@@ -8,6 +8,7 @@ import * as Schema from "effect/Schema";
88import * as Stream from "effect/Stream" ;
99import * as TestClock from "effect/testing/TestClock" ;
1010import * as NodeEvents from "node:events" ;
11+ import { vi } from "vite-plus/test" ;
1112
1213import * as DesktopBrowserHost from "./DesktopBrowserHost.ts" ;
1314
@@ -222,6 +223,48 @@ describe("DesktopBrowserHost", () => {
222223 } ) . pipe ( Effect . scoped ) ,
223224 ) ;
224225
226+ it . effect ( "never starts a stale native copy after navigation during the transform probe" , ( ) =>
227+ Effect . gen ( function * ( ) {
228+ const host = yield * DesktopBrowserHost . make ;
229+ const debuggee = makeDebuggee ( ) ;
230+ const probeStarted = Promise . withResolvers < void > ( ) ;
231+ const probe = Promise . withResolvers < boolean > ( ) ;
232+ let probing = true ;
233+ const capturePage = vi . fn ( async ( ) => ( { toDataURL : ( ) => "data:image/png;base64,eA==" } ) ) ;
234+ Object . assign ( debuggee . tab . webContents , {
235+ id : 42 ,
236+ capturePage,
237+ hostWebContents : {
238+ isDestroyed : ( ) => false ,
239+ executeJavaScript : async ( ) => {
240+ if ( probing ) {
241+ probing = false ;
242+ probeStarted . resolve ( ) ;
243+ return probe . promise ;
244+ }
245+ return true ;
246+ } ,
247+ } ,
248+ } ) ;
249+ host . attach ( key , debuggee . tab ) ;
250+ const replies = yield * watchReplies ( host ) ;
251+ yield * command ( host , 1 , "Page.captureScreenshot" ) ;
252+ yield * Effect . promise ( ( ) => probeStarted . promise ) ;
253+ yield * command ( host , 2 , "Page.captureScreenshot" ) ;
254+ const sent = debuggee . nextSend ( ) ;
255+ debuggee . navigate ( ) ;
256+ yield * Effect . promise ( ( ) => sent ) ;
257+ expect ( debuggee . sent ) . toEqual ( [ 2 ] ) ;
258+ expect ( capturePage ) . toHaveBeenCalledOnce ( ) ;
259+ probe . resolve ( true ) ;
260+ yield * settle ;
261+ expect ( capturePage ) . toHaveBeenCalledOnce ( ) ;
262+ expect ( yield * Queue . take ( replies ) ) . toBe ( 1 ) ;
263+ debuggee . release ( ) ;
264+ expect ( yield * Queue . take ( replies ) ) . toBe ( 2 ) ;
265+ } ) . pipe ( Effect . scoped ) ,
266+ ) ;
267+
225268 it . effect ( "drops screenshots a released relay left waiting" , ( ) =>
226269 Effect . gen ( function * ( ) {
227270 const host = yield * DesktopBrowserHost . make ;
0 commit comments