forked from AccessLint/screenreaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (43 loc) · 1.27 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { chromium } from 'playwright';
import { sh } from './shell.js'
const COMMANDS = {
launchVoiceOver: "/System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter",
stopVoiceOver: `./osascripts/stopVoiceover.js`,
setup: `./osascripts/setup.js`,
moveRight: './osascripts/moveRight.js',
getLastPhrase: './osascripts/getLastPhrase.js',
goToTop: './osascripts/goToTop.js',
}
export async function run({ url, limit, until, quiet }: {
url: string,
limit?: number,
until?: string,
quiet?: boolean,
}): Promise<string[]> {
let results = [];
const browser = await chromium.launch({ headless: false });
try {
const page = await browser.newPage();
await sh(COMMANDS.launchVoiceOver);
await sh(COMMANDS.setup);
await page.goto(url);
let i = 0;
let match = false;
while (i < limit && !match) {
await sh(COMMANDS.moveRight);
const { stdout } = await sh(COMMANDS.getLastPhrase);
if (!quiet) { process.stdout.write(stdout) };
results.push(stdout);
if (until && stdout.length > 0 && stdout.match(until)) {
match = true;
}
i++;
}
} catch(err) {
console.error(err);
} finally {
await sh(COMMANDS.stopVoiceOver);
await browser.close();
return results;
}
};