-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcdp.js
47 lines (39 loc) · 1.29 KB
/
cdp.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
function sleepyTime(sleepTime) {
return new Promise(resolve => {
if (sleepTime === undefined) {
sleepTime = Math.random() * 5000; // Random duration up to 5 seconds
}
setTimeout(resolve, sleepTime);
});
}
async function submitForm(inputQuery) {
let textarea = document.getElementById('prompt-textarea');
textarea.value = inputQuery;
await sleepyTime();
let inputEvent = new Event('input', {
'bubbles': true,
'cancelable': true
});
textarea.dispatchEvent(inputEvent);
await sleepyTime();
let submitButton = document.querySelector('[data-testid="send-button"]');
if (!submitButton.disabled) {
submitButton.click();
}
await sleepyTime(10000);
var elements = document.querySelectorAll('[data-testid^="conversation"]');
if (elements.length > 0) {
var lastElementText = elements[elements.length - 1].textContent || elements[elements.length - 1].innerText;
console.log("returning success: ", lastElementText)
return {
status: 'success',
output: lastElementText
};
} else {
console.log("OUTPUT:No matching elements found.");
return {
status: 'failure',
output: 'no output'
};
}
}