@@ -57,15 +57,26 @@ const MOVE_TO_TOP = {
5757 modifiers : [ WindowsModifiers . Control ] ,
5858} ;
5959
60+ type FocusBrowserParams = {
61+ applicationName : string ;
62+ pageTitle : string ;
63+ }
64+
65+ const hasFocus = ( { applicationName, pageTitle, windowTitle} :FocusBrowserParams & { windowTitle :string } ) => {
66+ return ( pageTitle . length && windowTitle . startsWith ( pageTitle ) ) || windowTitle . includes ( applicationName )
67+ }
68+
6069const focusBrowser = async ( {
6170 applicationName,
71+ pageTitle,
6272} : {
6373 applicationName : string ;
74+ pageTitle : string
6475} ) => {
6576 await nvdaPlaywright . perform ( nvdaPlaywright . keyboardCommands . reportTitle ) ;
6677 let windowTitle = await nvdaPlaywright . lastSpokenPhrase ( ) ;
6778
68- if ( windowTitle . includes ( applicationName ) ) {
79+ if ( hasFocus ( { applicationName, pageTitle , windowTitle } ) ) {
6980 return ;
7081 }
7182
@@ -78,7 +89,7 @@ const focusBrowser = async ({
7889 await nvdaPlaywright . perform ( nvdaPlaywright . keyboardCommands . reportTitle ) ;
7990 windowTitle = await nvdaPlaywright . lastSpokenPhrase ( ) ;
8091
81- if ( windowTitle . includes ( applicationName ) ) {
92+ if ( hasFocus ( { applicationName, pageTitle , windowTitle } ) ) {
8293 break ;
8394 }
8495 }
@@ -139,8 +150,9 @@ export const nvdaTest = test.extend<{
139150 nvdaPlaywright . keyboardCommands . exitFocusMode
140151 ) ;
141152
153+ const pageTitle = await page . title ( ) ;
142154 // Ensure application is brought to front and focused.
143- await focusBrowser ( { applicationName } ) ;
155+ await focusBrowser ( { applicationName, pageTitle } ) ;
144156
145157 // NVDA appears to not work well with Firefox when switching between
146158 // applications resulting in the entire browser window having NVDA focus
0 commit comments