简体   繁体   中英

How to wait until loading chrome tab's spinning wheel stops?

Is there an event to detect when the tab's loading spinning wheel on chrome stops ? I tried:

networkidle0, networkidle2, domcontentloaded

with no success

ex of page when I need to wait until it is loaded: https://www.translatetheweb.com/?from=&to=fr&ref=SERP&refd=www.bing.com&dl=fr&rr=UC&a=https%3a%2f%2fwww.247freepoker.com%2f

For now I use a 30 seconds waitFor

Regards

You could try to check the frame's _lifecycleEvents manually.

This function will resolve when that frame gets the networkIdle cycle event.

function waitForFrameLoaded(frame) {
    let fulfill;
    const promise = new Promise(x => fulfill = x);
    frame._frameManager.on('Events.FrameManager.LifecycleEvent', checkFrame)
    checkFrame(frame);
    return promise;

    function checkFrame(eventFrame) {
        if (eventFrame == frame && eventFrame._lifecycleEvents.has('networkIdle'))
        fulfill(frame);
    }
}

With that function, you could do something like this:

const browser = await puppeteer.launch({ headless: false});
const page = await browser.newPage();
await page.goto("https://www.translatetheweb.com/?from=&to=fr&ref=SERP&refd=www.bing.com&dl=fr&rr=UC&a=https%3a%2f%2fwww.247freepoker.com%2f");
const frameElement = await page.waitForSelector('#frmTgt')
const frame = await frameElement.contentFrame();
await waitForFrameLoaded(frame);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM