Skip to content

Instantly share code, notes, and snippets.

View programming-with-ia's full-sized avatar
🏠
Working from home

oimmi programming-with-ia

🏠
Working from home
View GitHub Profile
/**
* Helper function to wait for an element to appear or disappear.
* @param {string} selector - The CSS selector to query.
* @param {boolean} [shouldExist=true] - If true, waits for the element to exist. If false, waits for it to not exist.
* @param {number} [timeout=3000] - Max time to wait in milliseconds.
* @returns {Promise<Element|null>} A promise that resolves with the element (if found) or null (if timed out or disappearing).
*/
async function waitForElement(selector, shouldExist = true, timeout = 3000) {
const startTime = Date.now();
while (Date.now() - startTime < timeout) {