MCPcopy
hub / github.com/docsifyjs/docsify / waitForSelector

Function waitForSelector

test/helpers/wait-for.js:57–82  ·  view source on GitHub ↗

* Waits for specified CSS selector to be located in the DOM * * @param {String} cssSelector CSS selector to query for * @param {Object} options optional parameters * @returns {Promise} promise which resolves to first matching element

(cssSelector, options = {})

Source from the content-addressed store, hash-verified

55 * @returns {Promise} promise which resolves to first matching element
56 */
57function waitForSelector(cssSelector, options = {}) {
58 const settings = {
59 ...defaults,
60 ...options,
61 };
62
63 return new Promise((resolve, reject) => {
64 let timeElapsed = 0;
65
66 const int = setInterval(() => {
67 const elm = document.querySelector(cssSelector);
68 if (elm) {
69 clearInterval(int);
70 resolve(elm);
71 }
72
73 timeElapsed += settings.delay;
74
75 if (timeElapsed >= settings.timeout) {
76 const msg = `waitForSelector did not match CSS selector '${cssSelector}' (${settings.timeout} ms)`;
77
78 reject(msg);
79 }
80 }, settings.delay);
81 });
82}
83
84/**
85 * Waits for specified CSS selector to contain text content

Callers 2

waitForTextFunction · 0.85
docsifyInitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…