@@ -270,6 +270,8 @@ createRoot(document.getElementById('root')).render(createElement(Fixture));`,
270270 ?. getURL ( ) ?? null ,
271271 site
272272 )
273+ const focusedContentsUrl = ( ) =>
274+ shellApp . evaluate ( ( { webContents } ) => webContents . getFocusedWebContents ( ) ?. getURL ( ) )
273275 /** Trusted input into the page, the way the user's own mouse and keys arrive. */
274276 const userInput = ( selector : string , text = '' ) =>
275277 shellApp . evaluate (
@@ -436,6 +438,9 @@ createRoot(document.getElementById('root')).render(createElement(Fixture));`,
436438
437439 await check ( 'Escape keeps the draft and returns typing to the page' , async ( ) => {
438440 await userInput ( '#draft' )
441+ // The click is queued input: reloading before the page takes focus lets that focus land
442+ // after the modal's, leaving the Sim window without keyboard focus.
443+ await expect . poll ( focusedContentsUrl ) . toBe ( `${ site } /form` )
439444 await panelAction ( { action : 'reload' } )
440445 await expect ( shell . getByRole ( 'button' , { name : 'Stay' , exact : true } ) ) . toBeFocused ( )
441446 await shell . getByRole ( 'dialog' ) . screenshot ( {
@@ -451,11 +456,7 @@ createRoot(document.getElementById('root')).render(createElement(Fixture));`,
451456 message : `dialog ${ shown ?. requestId } was showing when Escape was pressed` ,
452457 } )
453458 . toBeNull ( )
454- await expect
455- . poll ( ( ) =>
456- shellApp . evaluate ( ( { webContents } ) => webContents . getFocusedWebContents ( ) ?. getURL ( ) )
457- )
458- . toBe ( `${ site } /form` )
459+ await expect . poll ( focusedContentsUrl ) . toBe ( `${ site } /form` )
459460 await shellApp . evaluate ( ( { webContents } ) => {
460461 const contents = webContents . getFocusedWebContents ( )
461462 if ( ! contents ) throw new Error ( 'Missing focused page' )
0 commit comments