@@ -58,7 +58,7 @@ vi.mock("./ServerBrowserContexts.ts", () => ({
5858 return makeEncoderPage ( ) as unknown as Page ;
5959 }
6060 async connectDesktopPage ( endpoint : string ) {
61- const context = makeContext ( ) ;
61+ const context = makeContext ( undefined , desktopPageUrl ) ;
6262 context . page . viewportSize . mockReturnValue ( null ) ;
6363 desktopConnections . push ( { endpoint, context } ) ;
6464 return { browser : { close : async ( ) => { } } , page : context . page as unknown as Page } ;
@@ -151,12 +151,12 @@ function fileChooserElement(accept: string) {
151151 } ;
152152}
153153
154- function makeContext ( onClose ?: ( context : BrowserContext ) => void ) {
154+ function makeContext ( onClose ?: ( context : BrowserContext ) => void , initialUrl = "about:blank" ) {
155155 const events = new NodeEvents . EventEmitter ( ) ;
156156 const nativeFileChooser = vi . fn ( ) ;
157157 const setChooserFiles = vi . fn ( async ( _files : unknown ) => { } ) ;
158158 const sessions : ReturnType < typeof makeSession > [ ] = [ ] ;
159- let url = "about:blank" ;
159+ let url = initialUrl ;
160160 let viewport : ReturnType < Page [ "viewportSize" ] > = { width : 1280 , height : 800 } ;
161161 const cssViewport = { width : 1920 , height : 1080 } ;
162162 let closed = false ;
@@ -299,6 +299,7 @@ let focusedFrame: ReturnType<typeof makeFrame> | null = null;
299299let contextFailure : Error | null = null ;
300300let initialNavigation : ( ( ) => Promise < void > ) | null = null ;
301301let desktopRendersNext = false ;
302+ let desktopPageUrl = "about:blank" ;
302303/** Replaces the answer to the desktop page's size reads. */
303304let desktopSizeAnswer : ( ( ) => Promise < Record < string , unknown > > ) | null = null ;
304305const desktopDetaches = new NodeEvents . EventEmitter ( ) ;
@@ -446,6 +447,7 @@ beforeEach(() => {
446447 focusedFrame = null ;
447448 desktopTabs . clear ( ) ;
448449 desktopRendersNext = false ;
450+ desktopPageUrl = "about:blank" ;
449451 desktopSizeAnswer = null ;
450452 desktopDetachReady = Promise . withResolvers < void > ( ) ;
451453 desktopReleased = Promise . withResolvers < void > ( ) ;
@@ -563,6 +565,33 @@ it.effect("a tab the desktop does not draw is marked headless, so the desktop st
563565 ) . pipe ( Effect . provide ( layer ) ) ,
564566) ;
565567
568+ it . effect ( "a desktop page that loaded before the server attached reports its loaded title" , ( ) =>
569+ Effect . scoped (
570+ Effect . gen ( function * ( ) {
571+ const { broker } = yield * ready ;
572+ const manager = yield * Manager . PreviewManager ;
573+ const events = yield * manager . subscribeEvents ;
574+ desktopRendersNext = true ;
575+ desktopPageUrl = "https://example.com/loaded" ;
576+ const opened = yield * broker . invoke < PreviewAutomationStatus > ( {
577+ scope,
578+ operation : "open" ,
579+ input : { url : desktopPageUrl , reuseExistingTab : false , show : false } ,
580+ } ) ;
581+ let event = yield * PubSub . take ( events ) ;
582+ while ( event . type !== "navigated" || event . tabId !== opened . tabId ) {
583+ event = yield * PubSub . take ( events ) ;
584+ }
585+
586+ expect ( event . snapshot . navStatus ) . toEqual ( {
587+ _tag : "Success" ,
588+ url : "https://example.com/loaded" ,
589+ title : "test page" ,
590+ } ) ;
591+ } ) ,
592+ ) . pipe ( Effect . provide ( layer ) ) ,
593+ ) ;
594+
566595it . live . each ( [
567596 { method : "goto" as const , message : { type : "navigate" , url : "http://10.255.255.1/" } } ,
568597 { method : "goBack" as const , message : { type : "history" , delta : - 1 } } ,
0 commit comments