@@ -36,6 +36,7 @@ const fixture = Bun.serve({
3636 const received = [];
3737 window.addEventListener('message', event => {
3838 if (event.source !== parent || !event.origin.startsWith('chrome-extension://')) return;
39+ if (event.data.type === 'e2e-barrier') document.body.dataset.barrierId = event.data.id;
3940 if (event.data.type === 'context' && event.data.sessionId === document.body.dataset.sessionId) {
4041 if (document.body.dataset.ignoreCaptures) return;
4142 received.push(event.data.snapshot);
@@ -206,6 +207,19 @@ try {
206207 }
207208 } )
208209
210+ const settleMessages = async ( ) => {
211+ const barrierId = generateId ( )
212+ await panel . evaluate (
213+ ( { origin, barrierId } ) => {
214+ const target = document . querySelector ( 'iframe' ) ?. contentWindow
215+ if ( ! target ) throw new Error ( 'Missing hosted frame' )
216+ target . postMessage ( { type : 'e2e-barrier' , id : barrierId } , origin )
217+ } ,
218+ { origin, barrierId }
219+ )
220+ await app . waitForFunction ( ( id ) => document . body . dataset . barrierId === id , barrierId )
221+ }
222+
209223 await check ( 'Capture stays local until the trusted hosted frame is ready' , async ( ) => {
210224 await capture ( )
211225 await panel . getByRole ( 'status' ) . filter ( { hasText : 'Waiting for Sim' } ) . waitFor ( )
@@ -225,6 +239,7 @@ try {
225239 } ) ,
226240 receiverSessionId
227241 )
242+ await settleMessages ( )
228243 assert ( ( await snapshots ( ) ) . length === 0 , 'Wrong-origin readiness was accepted' )
229244 const wrongFrameDelivered = panel . evaluate (
230245 ( ) =>
@@ -246,6 +261,7 @@ try {
246261 document . body . append ( child )
247262 } , receiverSessionId )
248263 await wrongFrameDelivered
264+ await settleMessages ( )
249265 assert ( ( await snapshots ( ) ) . length === 0 , 'Wrong-frame readiness was accepted' )
250266 await page . evaluate ( ( ) => {
251267 document . body . textContent = 'SECOND_CAPTURE_SENTINEL'
0 commit comments