Extension.js
/**
* Wait for an element before resolving a promise
* @param {String} querySelector - Selector of element to wait for
* @param {Integer} timeout - Milliseconds to wait before timing out, or 0 for no timeout              
*/
Wait for an element before resolving a promise
Wait for an element before resolving a promise
function waitForElement(querySelector, timeout=0) {
    const startTime = new Date().getTime();
    return new Promise((resolve, reject)=>{
        const timer = setInterval(()=>{
            const now = new Date().getTime();
            if(document.querySelector(querySelector)){
                clearInterval(timer);
                resolve();
            }else if(timeout && now - startTime >= timeout){
                clearInterval(timer);
                reject(querySelector);
            }
        }, 200);
    });
 }
function waitForElement ( querySelector , timeout = 0 ) { const startTime = new Date ( ) . getTime ( ) ; return new Promise ( ( resolve , reject ) => { const timer = setInterval ( ( ) => { const now = new Date ( ) . getTime ( ) ; if ( document . querySelector ( querySelector ) ) { clearInterval ( timer ) ; resolve ( ) ; } else if ( timeout && now - startTime >= timeout ) { clearInterval ( timer ) ; reject ( querySelector ) ; } } , 200 ) ; } ) ; }
Wait for an element before resolving a promise
Wait for an element before resolving a promise