@@ -65,8 +65,8 @@ describe("CDP relay", () => {
6565 ] ) ;
6666 pending [ 0 ] ! ( ) ;
6767 await settle ( ) ;
68- expect ( send ) . toHaveBeenNthCalledWith ( 1 , "Page.captureScreenshot" , { } , undefined ) ;
69- expect ( send ) . toHaveBeenNthCalledWith ( 2 , "DOM.enable" , { } , "iframe-session" ) ;
68+ expect ( send ) . toHaveBeenNthCalledWith ( 1 , "Page.captureScreenshot" , { } , undefined , undefined ) ;
69+ expect ( send ) . toHaveBeenNthCalledWith ( 2 , "DOM.enable" , { } , "iframe-session" , undefined ) ;
7070 expect ( written . at ( - 1 ) ) . toEqual ( {
7171 id : 5 ,
7272 result : { method : "Page.captureScreenshot" } ,
@@ -92,7 +92,30 @@ describe("CDP relay", () => {
9292 } ) ,
9393 ) ;
9494 await settle ( ) ;
95- expect ( send . mock . calls ) . toEqual ( [ [ "Runtime.runIfWaitingForDebugger" , { } , "iframe-session" ] ] ) ;
95+ expect ( send . mock . calls ) . toEqual ( [
96+ [ "Runtime.runIfWaitingForDebugger" , { } , "iframe-session" , undefined ] ,
97+ ] ) ;
98+ } ) ;
99+
100+ // Playwright enables focus emulation on every page it connects to, and Chromium then
101+ // counts the guest as captured: a preview the panel hides keeps its timers unthrottled.
102+ it ( "acknowledges Playwright's focus emulation without forcing it onto the guest" , async ( ) => {
103+ const send = vi . fn ( async ( ) => ( { } ) ) ;
104+ const written : Array < Record < string , unknown > > = [ ] ;
105+ const relay = createCdpRelayConnection ( makeTarget ( send ) , ( raw ) =>
106+ written . push ( JSON . parse ( raw ) ) ,
107+ ) ;
108+ relay . receive (
109+ JSON . stringify ( {
110+ id : 1 ,
111+ method : "Emulation.setFocusEmulationEnabled" ,
112+ params : { enabled : true } ,
113+ sessionId : "t3-preview-page" ,
114+ } ) ,
115+ ) ;
116+ await settle ( ) ;
117+ expect ( written ) . toEqual ( [ { id : 1 , result : { } , sessionId : "t3-preview-page" } ] ) ;
118+ expect ( send ) . not . toHaveBeenCalled ( ) ;
96119 } ) ;
97120
98121 it ( "routes tab events to the page session once the page is announced" , async ( ) => {
@@ -147,7 +170,7 @@ describe("CDP relay extra sessions", () => {
147170 expect ( written . find ( ( m ) => m [ "id" ] === 4 ) ) . toHaveProperty ( "error" ) ;
148171 relay . receive ( JSON . stringify ( { id : 5 , method : "Page.startScreencast" , sessionId : extra } ) ) ;
149172 await settle ( ) ;
150- expect ( send ) . toHaveBeenLastCalledWith ( "Page.startScreencast" , { } , undefined ) ;
173+ expect ( send ) . toHaveBeenLastCalledWith ( "Page.startScreencast" , { } , undefined , extra ) ;
151174 written . length = 0 ;
152175 relay . event ( "Page.screencastFrame" , { data : "x" } , undefined ) ;
153176 expect ( written . map ( ( m ) => m [ "sessionId" ] ) ) . toEqual ( [ "t3-preview-page" , extra ] ) ;
0 commit comments