Skip to content

Commit c483ca4

Browse files
authored
fix: resolve nvda.navigateToWebContent() infinite window switching (#39)
1 parent 6790586 commit c483ca4

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/nvdaTest.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,27 @@ type FocusBrowserParams = {
6262
pageTitle: string;
6363
};
6464

65+
const cleanString = (str: string): string =>
66+
str
67+
.toLowerCase()
68+
// REF: https://github.com/nvaccess/nvda/blob/master/source/locale/en/symbols.dic
69+
.replace(/[|¦:;'"`\-·_()[\]{}\\^~]/g, " ")
70+
.replace(/\s+/g, " ")
71+
.trim();
72+
6573
const hasFocus = ({
6674
applicationName,
6775
pageTitle,
6876
windowTitle,
6977
}: FocusBrowserParams & { windowTitle: string }) => {
78+
const cleanedApplicationName = cleanString(applicationName);
79+
const cleanedPageTitle = cleanString(pageTitle);
80+
const cleanedWindowTitle = cleanString(windowTitle);
81+
7082
return (
71-
(pageTitle.length && windowTitle.startsWith(pageTitle)) ||
72-
windowTitle.includes(applicationName)
83+
(cleanedPageTitle.length &&
84+
cleanedWindowTitle.startsWith(cleanedPageTitle)) ||
85+
cleanedWindowTitle.includes(cleanedApplicationName)
7386
);
7487
};
7588

@@ -161,7 +174,10 @@ export const nvdaTest = test.extend<{
161174

162175
const pageTitle = await page.title();
163176
// Ensure application is brought to front and focused.
164-
await focusBrowser({ applicationName, pageTitle });
177+
await focusBrowser({
178+
applicationName,
179+
pageTitle,
180+
});
165181

166182
// Ensure the document is ready and focused.
167183
await page.bringToFront();

0 commit comments

Comments
 (0)