Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to wait for network to idle for X seconds? #3305

Closed
mranosa opened this issue Sep 25, 2018 · 3 comments
Closed

Is there a way to wait for network to idle for X seconds? #3305

mranosa opened this issue Sep 25, 2018 · 3 comments

Comments

@mranosa
Copy link

mranosa commented Sep 25, 2018

I am playing around with puppeteer and am trying to find a way for me to capture a users experience for a youtube video. I am able to make things work already, but if an ad video shows up before the video itself, my whole code gets broken.

My theory is that if I can increase the wait for network idle for X more seconds my code would work. Any workaround for this is also highly appreciated.

Thanks a lot! 😄

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Sep 25, 2018

Maybe something like this?

const idleSpan = 60000;
let lastRequest = Date.now();

await page.setRequestInterception(true);
page.on('request', registerRequest);

while (Date.now() - lastRequest < idleSpan) await page.waitFor(1000);

page.removeListener('request', registerRequest);
await page.setRequestInterception(false);

function registerRequest(request) {
  request.continue();
  lastRequest = Date.now();
}

@markedmiston
Copy link

#3083 is working on exposing networkidle0 and networkidle2 but you can emulate it with the code from #1353 (comment). In your case you can adjust the timeout by replacing X in waitForNetworkIdle(page, X, 0)

@mranosa
Copy link
Author

mranosa commented Sep 26, 2018

awesome! thanks a lot!

@mranosa mranosa closed this as completed Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants