@@ -187,6 +187,43 @@ describe("CDP relay popups", () => {
187187 const resultOf = ( written : Array < Record < string , unknown > > , id : number ) =>
188188 written . find ( ( message ) => message [ "id" ] === id ) ! ;
189189
190+ it ( "detaches an announced popup session without closing its native window or detaching the opener" , async ( ) => {
191+ const pageSend = vi . fn ( async ( ) => ( { } ) ) ;
192+ const popupSend = vi . fn ( async ( ) => ( { } ) ) ;
193+ const closePopup = vi . fn ( ) ;
194+ const written : Array < Record < string , unknown > > = [ ] ;
195+ const relay = makeRelay ( makeTarget ( pageSend ) , ( raw ) => written . push ( JSON . parse ( raw ) ) ) ;
196+ relay . addPopup ( makePopup ( "POPUP" , popupSend , closePopup ) ) ;
197+ relay . receive ( JSON . stringify ( { id : 1 , method : "Target.setAutoAttach" } ) ) ;
198+ await settle ( ) ;
199+ relay . receive (
200+ JSON . stringify ( {
201+ id : 2 ,
202+ method : "Target.detachFromTarget" ,
203+ params : { sessionId : "t3-preview-popup-1" } ,
204+ } ) ,
205+ ) ;
206+ relay . receive (
207+ JSON . stringify ( {
208+ id : 3 ,
209+ method : "Target.detachFromTarget" ,
210+ params : { sessionId : "t3-preview-page" } ,
211+ } ) ,
212+ ) ;
213+ await settle ( ) ;
214+ expect ( resultOf ( written , 2 ) ) . toHaveProperty ( "result" ) ;
215+ relay . receive (
216+ JSON . stringify ( { id : 4 , method : "Runtime.evaluate" , sessionId : "t3-preview-popup-1" } ) ,
217+ ) ;
218+ relay . receive ( JSON . stringify ( { id : 5 , method : "Page.enable" , sessionId : "t3-preview-page" } ) ) ;
219+ await settle ( ) ;
220+ expect ( resultOf ( written , 4 ) ) . toHaveProperty ( "error" ) ;
221+ expect ( popupSend ) . not . toHaveBeenCalled ( ) ;
222+ expect ( closePopup ) . not . toHaveBeenCalled ( ) ;
223+ expect ( pageSend ) . toHaveBeenCalledExactlyOnceWith ( "Page.enable" , { } , undefined , undefined ) ;
224+ expect ( resultOf ( written , 5 ) ) . toHaveProperty ( "result" ) ;
225+ } ) ;
226+
190227 it . each ( [ "browser" , "popup" , "child" ] ) (
191228 "detaches a popup child through its %s session without affecting the other sessions" ,
192229 async ( source ) => {
0 commit comments