forked from hello-robot/stretch_web_interface
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart_operator_browser.js
executable file
·59 lines (47 loc) · 1.67 KB
/
start_operator_browser.js
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
53
54
55
56
57
58
59
#!/usr/bin/env node
const { chromium } = require('playwright');
const logId = 'start_operator_browser.js';
let robotHostname = "localhost";
if (process.argv.length > 2) {
robotHostname = process.argv[2]
}
(async () => {
const navigation_timeout_ms = 30000; //30 seconds (default is 30 seconds)
const min_idle_time = 1000;
var try_again = false;
var num_tries = 0;
var max_tries = 50; // -1 means try forever
///////////////////////////////////////////////
// sleep code from
// https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
///////////////////////////////////////////////
const browser = await chromium.launch({
headless: false, // default is true
ignoreHTTPSErrors: true, // avoid ERR_CERT_COMMON_NAME_INVALID
defaultViewport: null,
args: ['--use-fake-ui-for-media-stream'] //gives permission to access the robot's cameras and microphones (cleaner and simpler than changing the user directory)
});
const page = await browser.newPage();
while (try_again) {
try {
await page.goto(`https://${robotHostname}/login`);
console.log(logId + ': finished loading');
try_again = false;
} catch (e) {
console.log(logId + ': trying again');
console.log(e);
await sleep(200);
try_again = true;
}
}
console.log(logId + ': type username');
await page.$eval('#inputUsername', el => el.value = 'o1');
console.log(logId + ': type password');
await page.$eval('#inputPassword', el => el.value = 'xXTgfdH8');
console.log(logId + ': click submit');
await page.click('#submitButton');
console.log(logId + ': start script complete');
})();