@@ -85,7 +85,9 @@ const PNG_HEADER = (() => {
8585
8686function makeSession ( frame ?: ReturnType < typeof makeFrame > ) {
8787 const events = new NodeEvents . EventEmitter ( ) ;
88+ const metrics = { ratio : 2 , width : 1280 , height : 800 } ;
8889 return {
90+ metrics,
8991 on : vi . fn ( ( name : string , listener : ( ) => void ) => events . on ( name , listener ) ) ,
9092 emit : ( name : string ) => events . emit ( name ) ,
9193 detach : vi . fn ( async ( ) => { } ) ,
@@ -100,13 +102,18 @@ function makeSession(frame?: ReturnType<typeof makeFrame>) {
100102 if ( method === "Runtime.callFunctionOn" ) return { result : { value : PNG_HEADER } } ;
101103 if ( method === "Page.getFrameTree" ) return { frameTree : { frame : { id : "main" } } } ;
102104 if ( method === "Page.createIsolatedWorld" ) {
105+ const worldName = ( input as { worldName ?: string } ) . worldName ;
103106 return {
104- executionContextId : ( input as { worldName ?: string } ) . worldName === "t3-preview" ? 1 : 7 ,
107+ executionContextId :
108+ worldName === "t3-preview" ? 1 : worldName === "t3-preview-metrics" ? 9 : 7 ,
105109 } ;
106110 }
107111 if ( method === "Runtime.evaluate" && ( input as { contextId ?: number } ) . contextId === 1 ) {
108112 return { result : { value : [ ] } } ;
109113 }
114+ if ( method === "Runtime.evaluate" && ( input as { contextId ?: number } ) . contextId === 9 ) {
115+ return { result : { value : metrics } } ;
116+ }
110117 if ( method === "Page.addScriptToEvaluateOnNewDocument" ) frame ?. recording . resolve ( ) ;
111118 if ( method === "Input.dispatchKeyEvent" && ( input as { commands ?: unknown } ) . commands ) {
112119 if ( focusedFrame ) focusedFrame . copy = keyCopy || focusedFrame . copy ;
@@ -159,7 +166,7 @@ function makeContext(onClose?: (context: BrowserContext) => void) {
159166 frames : ( ) => [ page ] ,
160167 url : ( ) => url ,
161168 title : vi . fn ( async ( ) => "test page" ) ,
162- viewportSize : ( ) => viewport ,
169+ viewportSize : vi . fn < Page [ "viewportSize" ] > ( ( ) => viewport ) ,
163170 setViewportSize : vi . fn ( async ( size : typeof viewport ) => {
164171 viewport = size ;
165172 } ) ,
@@ -627,6 +634,33 @@ it.live("enforces provider ownership and explicit targets when a session has mul
627634 ) . pipe ( Effect . provide ( layer ) ) ,
628635) ;
629636
637+ it . live ( "sends desktop viewport dimensions when Playwright has no emulated viewport" , ( ) =>
638+ Effect . scoped (
639+ Effect . gen ( function * ( ) {
640+ desktopRendersNext = true ;
641+ const { browser, tabId } = yield * ready ;
642+ const { page } = desktopConnections [ 0 ] ! . context ;
643+ page . viewportSize . mockReturnValue ( null ) ;
644+ page . setViewportSize . mockClear ( ) ;
645+
646+ const viewer = yield * browser . attachViewer ( viewerInput ( tabId , true ) ) ;
647+ const outputs = yield * Queue . takeAll ( viewer . output ) ;
648+ expect ( outputs ) . toContainEqual ( { _tag : "viewport" , width : 1280 , height : 800 } ) ;
649+
650+ const session = desktopConnections [ 0 ] ! . context . sessions [ 0 ] ! ;
651+ session . metrics . width = 960 ;
652+ session . metrics . height = 600 ;
653+ session . emit ( "Page.frameResized" ) ;
654+ expect ( yield * Queue . take ( viewer . output ) ) . toEqual ( {
655+ _tag : "viewport" ,
656+ width : 960 ,
657+ height : 600 ,
658+ } ) ;
659+ expect ( page . setViewportSize ) . not . toHaveBeenCalled ( ) ;
660+ } ) ,
661+ ) . pipe ( Effect . provide ( layer ) ) ,
662+ ) ;
663+
630664it . live ( "streams to a read-only viewer without allowing takeover, input, or viewport changes" , ( ) =>
631665 Effect . scoped (
632666 Effect . gen ( function * ( ) {
0 commit comments