jtassin / pending-xhr-puppeteer

Small tool to wait that all xhr are finished in puppeteer
MIT License
276 stars 19 forks source link

Destroy listener on page change #27

Open jtassin opened 5 years ago

gtyang commented 5 years ago

any progress on this issue?

pcordon commented 4 years ago

Looking for this as well. Any news?

agabhane commented 4 years ago

@jtassin Ideally the listener should get disposed when waitForAllXhrFinished() promise gets resolved. Moreover page should start listening when we make call to waitForAllXhrFinished() instead of in constructor. This will stop unnecessary listening of requests.

Using this mechanism, we can use the same coding pattern as suggested by puppeteer -

await Promise.all([
  pendingXHR.waitForAllXhrFinished(), // Listeners will start listening requests
  page.click('a.my-link') // Click happened which triggered requests
]);

What do you think? I can raise the merge request if we agree.

agabhane commented 4 years ago

I have created new package @agabhane/puppeteer-pending-requests with above requirements and few enhancements.

jtassin commented 4 years ago

@agabhane your idea makes sense

Their is a PR for a cleanup behaviour : https://github.com/jtassin/pending-xhr-puppeteer/pull/112 more or less like your idea "listener should get disposed when waitForAllXhrFinished() promise gets resolved".

Your idea in puppeteer-pending-requests to add a timer is very good.