MCPcopy Create free account
hub / github.com/Surfer-Org/Protocol / waitForElement

Function waitForElement

desktop/src/main/preloadFunctions.js:11–45  ·  view source on GitHub ↗
(
  id,
  selector,
  elementName,
  multipleElements = false,
  timeout = 10000,
)

Source from the content-addressed store, hash-verified

9};
10
11function waitForElement(
12 id,
13 selector,
14 elementName,
15 multipleElements = false,
16 timeout = 10000,
17) {
18
19 if (!multipleElements){
20 customConsoleLog(id, `Waiting for ${elementName}`);
21 }
22
23 return new Promise((resolve) => {
24 const startTime = Date.now();
25
26 const checkElement = () => {
27 const element = multipleElements
28 ? document.querySelectorAll(selector)
29 : document.querySelector(selector);
30 if (element) {
31 if (!multipleElements){
32 customConsoleLog(id, `Found ${elementName}`);
33 }
34 resolve(element);
35 } else if (Date.now() - startTime >= timeout) {
36 customConsoleLog(id, `Timeout waiting for ${elementName}`);
37 resolve(null);
38 } else {
39 setTimeout(checkElement, 100);
40 }
41 };
42
43 checkElement();
44 });
45}
46
47async function wait(seconds) {
48 return new Promise((resolve) => {

Callers 6

exportTwitterFunction · 0.85
exportChatgptFunction · 0.85
checkEmailsFunction · 0.85
exportGmailFunction · 0.85
checkEmailsFunction · 0.85
exportYoutubeFunction · 0.85

Calls 2

customConsoleLogFunction · 0.85
checkElementFunction · 0.85

Tested by

no test coverage detected