@@ -360,12 +360,10 @@ function makeEncoderPage() {
360360 document : { createElement : ( tag : string ) => ( tag === "video" ? video : canvas ) } ,
361361 Path2D : function Path2D ( ) { } ,
362362 MediaRecorder : FakeMediaRecorder ,
363- createImageBitmap : async ( blob : Blob ) => ( {
364- width : 1280 ,
365- height : 800 ,
366- pixels : await blob . text ( ) ,
367- close ( ) { } ,
368- } ) ,
363+ createImageBitmap : async ( blob : Blob ) => {
364+ await decodeGate ?. promise ;
365+ return { width : 1280 , height : 800 , pixels : await blob . text ( ) , close ( ) { } } ;
366+ } ,
369367 atob,
370368 btoa,
371369 Blob,
@@ -386,6 +384,7 @@ function makeEncoderPage() {
386384const contexts : ReturnType < typeof makeContext > [ ] = [ ] ;
387385let encoderPageOverride : Page | undefined ;
388386const encoderStreams : Array < { frameRate : number | undefined ; bitsPerSecond : number } > = [ ] ;
387+ let decodeGate : PromiseWithResolvers < void > | null = null ;
389388const contextRequests : Array < { profileId : string ; isolated : boolean } > = [ ] ;
390389let contextGate : PromiseWithResolvers < void > | null = null ;
391390let heldStill : ( ( ) => Promise < void > ) | null = null ;
@@ -571,6 +570,7 @@ beforeEach(() => {
571570 contexts . length = 0 ;
572571 encoderPageOverride = undefined ;
573572 encoderStreams . length = 0 ;
573+ decodeGate = null ;
574574 contextRequests . length = 0 ;
575575 contextGate = null ;
576576 heldStill = null ;
@@ -1077,6 +1077,32 @@ it.effect.each([
10771077 ) . pipe ( Effect . provide ( layer ) ) ,
10781078) ;
10791079
1080+ // Chrome stops sending screencast frames while too many are unacked.
1081+ it . effect ( "recordings ack screencast frames without waiting for the encoder to decode them" , ( ) =>
1082+ Effect . scoped (
1083+ Effect . gen ( function * ( ) {
1084+ const { broker, tabId } = yield * ready ;
1085+ yield * broker . invoke ( { scope, tabId, operation : "recordingStart" , input : { } } ) ;
1086+ const session = contexts [ 0 ] ! . sessions . find ( ( candidate ) =>
1087+ candidate . send . mock . calls . some ( ( [ method ] ) => method === "Page.startScreencast" ) ,
1088+ ) ! ;
1089+ const gate = Promise . withResolvers < void > ( ) ;
1090+ decodeGate = gate ;
1091+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => gate . resolve ( ) ) ) ;
1092+ for ( const sessionId of [ 1 , 2 , 3 ] ) {
1093+ session . emit ( "Page.screencastFrame" , {
1094+ data : Buffer . from ( `frame ${ sessionId } ` ) . toString ( "base64" ) ,
1095+ sessionId,
1096+ metadata : { deviceWidth : 1280 } ,
1097+ } ) ;
1098+ }
1099+ expect (
1100+ session . send . mock . calls . filter ( ( [ method ] ) => method === "Page.screencastFrameAck" ) ,
1101+ ) . toHaveLength ( 3 ) ;
1102+ } ) ,
1103+ ) . pipe ( Effect . provide ( layer ) ) ,
1104+ ) ;
1105+
10801106it . effect . each ( [ { truncated : false } , { truncated : true } ] ) (
10811107 "saves a large recording as a binary download and removes its staged file (truncated: $truncated)" ,
10821108 ( { truncated } ) =>
0 commit comments