{"_id":"@agabhane/puppeteer-pending-requests","_rev":"2-6fa32a625e9106d6006081758280d622","name":"@agabhane/puppeteer-pending-requests","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@agabhane/puppeteer-pending-requests","version":"1.0.0","description":"Wait for pending requests to finish in puppeteer","main":"dist/index.js","scripts":{"start":"tsc -w","build":"tsc"},"repository":{"type":"git","url":"git+https://github.com/agabhane/puppeteer-pending-requests.git"},"keywords":["puppeteer","pendingrequest","request","pendingxhr","xhr"],"author":{"name":"ashishgabhane1@gmail.com"},"license":"ISC","bugs":{"url":"https://github.com/agabhane/puppeteer-pending-requests/issues"},"homepage":"https://github.com/agabhane/puppeteer-pending-requests#readme","devDependencies":{"@types/puppeteer":"^2.0.0","typescript":"^3.7.4"},"gitHead":"8d7372c30b1defc13de94221811d916bbc02be88","_id":"@agabhane/puppeteer-pending-requests@1.0.0","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"integrity":"sha512-1IioyqLI0ExZ3aEAuhXu1DBsRS3s7ABZQ8uRwxJSeh6F3ZWYRKDWYM+c8YPXzB1pIGQLvb6fmSl3V7XfBXgI+Q==","shasum":"2670fc6b7bfc2f6f5734c9f11593a047eaeb2568","tarball":"https://registry.npmjs.org/@agabhane/puppeteer-pending-requests/-/puppeteer-pending-requests-1.0.0.tgz","fileCount":10,"unpackedSize":14038,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeEj1oCRA9TVsSAnZWagAAXeoQAIYcRORtbTQOL86Cjx/D\nGI0t9ikQmiXTUmZMOiMsDlgp+1wBgO59WvMyj7IETaa9ZoFTrV2MJuH7cEq5\nhFu7va7KouZwboZxtL17U0iGfdKCXCENTECTHwuK4oAYPVXgd+2RBg+QIKCR\nayVQ9UXBB7A2LKWHFXGXiX3x4t1djS2JB2ZPZ1IlcGQ5cEikNFh5Bb1RtjKH\n4pYTV7SQNRet3oj7iZgP9yTsy6nQcTf4mKrWcRRqHyec8svpcaM6+YaHBrm3\nw1dyh6CRtfttbmlnedPtTOuWIODLntAnR2BFNeOuxap88a4jTVtjTBMYQs9Y\nNX2vHz6MzBsdkXaLSYsz2o0BCx6rwuDqAfltf931gKzNQzjULQdsRvKmMFng\nNs6j5ypBlp/cVtmaXiL0ZIFPvLqUMP80OQhv2LgmiSGx//grvNa2zweeQIBu\nqvXDJSSYmDqDfvQxnvsDgPUifqlZmShZRH/R+vvlhMcwTyL0XVuFdrco1DLr\nN6fVGtaPwIf6CswYJOK+EB8Wy8SEgid2Hv195hesUPvnC9TqQbYkC+WtS1he\nOPo1uNiL/G8Q4Z9wS3BFe3Q9JEn9rg2OoTdSUQDujg9/Vi5JPERRg4WtJ2m0\nhUaG6t3H9nxzr5Q//mmKkq0PD968RW90VK5WSwkolXWeErva1Al2R9hw2Fai\nVMC3\r\n=oFq3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIErqry8FK8dZvV2lnLT9Sc8csCXV3dyEsH7/R2EDRyDmAiEAynVIAHtcrMvHgVjeAHr1mrQDnJ/yD9Eio74dSQoW+cM="}]},"maintainers":[{"name":"agabhane","email":"ashishgabhane1@gmail.com"}],"_npmUser":{"name":"agabhane","email":"ashishgabhane1@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/puppeteer-pending-requests_1.0.0_1578253672164_0.6186842594640105"},"_hasShrinkwrap":false},"1.0.1":{"name":"@agabhane/puppeteer-pending-requests","version":"1.0.1","description":"Wait for pending requests to finish in puppeteer","main":"dist/index.js","scripts":{"start":"tsc -w","build":"tsc"},"repository":{"type":"git","url":"git+https://github.com/agabhane/puppeteer-pending-requests.git"},"keywords":["puppeteer","pendingrequest","request","pendingxhr","xhr"],"author":{"name":"ashishgabhane1@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/agabhane/puppeteer-pending-requests/issues"},"homepage":"https://github.com/agabhane/puppeteer-pending-requests#readme","devDependencies":{"@types/puppeteer":"^2.0.0","typescript":"^3.7.4"},"gitHead":"8d7372c30b1defc13de94221811d916bbc02be88","_id":"@agabhane/puppeteer-pending-requests@1.0.1","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"integrity":"sha512-e2DB3Lao30pQF4rcHjsLBym1lYy8N9kXnMR/ZKYr+n6yfmBxrajJEzMfkfzWe9bnC/PUQFSMF7oPMYCmI2XG3g==","shasum":"559b16c0dd015f9ce86be02201f66eb3bc36c8b2","tarball":"https://registry.npmjs.org/@agabhane/puppeteer-pending-requests/-/puppeteer-pending-requests-1.0.1.tgz","fileCount":10,"unpackedSize":14038,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeEj7SCRA9TVsSAnZWagAAM14P/RIdfLpoQ0zpjZrtzKHA\n5mP53cK2M7RO3AWegP9nneB2jY8B4pW/ezSrPv4aGyJE8Y/hZWaACrGZ+kwP\nxaoOKsIrLkYJg6f0dUBJtHqrWV/AzVG+o+d026Mi6X4etqIVwJ4/2f8SkZEt\nQowN6EkjpM/yG0wT7T0l+9l8TvPFX766SHDjlQcTe9cEkiI9PGJW7JaogFh4\n0oAHO3F7v/xvAR38DWaMSfUxUddSr2eqg2zASJdyREJSfYmiLQMapmbgMQA+\nGKb0YNZYdncxJVRvGX3+giFaCdq+lFDmLVBi0O5PKSCyl+rocT64iY3OogED\nwkLcf0XnDTHgpyUXxgQnM4CqxNYlXdt3N630s0SRf/oaU7YdGXpYKCdpaxuy\nYouRFmcsAZ0vsAegGTzijdM8nMCdEnbBTNwMmER//Uk14R8A4CzVrYQ6jM/Z\ncNu2XbaoIVGP+uf154WB5ipFQT5kiQZL0HjUlk/s88UCQ9kvXAntMU1CCRne\nCivyNyrL8wNZmd+dvhp7wMbo5qSFjo+A3EAGc3Vifo9PQQMyTxYTrAWxI7tP\nkJ8xnBVIaJS0tX1TlURwaDBJm1+06u/mrxI4RWk/tLnxzJwiuXZxcz1iNKTV\nqb1kT60qHs6JfYASWzs9tmU8UYmDzFbpnpfmJChaf9Dm42sL57mqOpwWfJA+\ndnZl\r\n=uxZw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCQt677fKycxB7ay1aaMEeb6sIfLkSPiofdNMX2i3MXBAIhAO0pRuNpWTIlRW3UmGENYhcmn+hd97q3NCqZqA6hh18b"}]},"maintainers":[{"name":"agabhane","email":"ashishgabhane1@gmail.com"}],"_npmUser":{"name":"agabhane","email":"ashishgabhane1@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/puppeteer-pending-requests_1.0.1_1578254033872_0.6134644777340699"},"_hasShrinkwrap":false}},"time":{"created":"2020-01-05T19:47:52.087Z","1.0.0":"2020-01-05T19:47:52.330Z","modified":"2022-04-04T11:53:50.209Z","1.0.1":"2020-01-05T19:53:53.992Z"},"maintainers":[{"name":"agabhane","email":"ashishgabhane1@gmail.com"}],"description":"Wait for pending requests to finish in puppeteer","homepage":"https://github.com/agabhane/puppeteer-pending-requests#readme","keywords":["puppeteer","pendingrequest","request","pendingxhr","xhr"],"repository":{"type":"git","url":"git+https://github.com/agabhane/puppeteer-pending-requests.git"},"author":{"name":"ashishgabhane1@gmail.com"},"bugs":{"url":"https://github.com/agabhane/puppeteer-pending-requests/issues"},"license":"MIT","readme":"# puppeteer-pending-requests\r\n## Introduction\r\nProvides utility to wait for network to be idle for passed time.\r\n\r\nThis utility basically checks for zero pending requests and there is no new request for passed time.\r\n\r\n## Install\r\n```\r\nnpm install @agabhane/puppeteer-pending-requests\r\n```\r\n\r\n## Usage\r\nImport `@agabhane/puppeteer-pending-requests` in your code\r\n```\r\nconst { PuppeteerPendingRequests } = require('@agabhane/puppeteer-pending-requests');\r\n```\r\n\r\nCreate an instance by passing Puppeteer page\r\n```\r\nlet puppeteerPendingRequests = new PuppeteerPendingRequests(page);\r\n```\r\n\r\nUse `waitForNetworkIdle()` function to wait for network to be idle for passed time.\r\n```\r\nawait waitForNetworkIdle(500);\r\n```\r\n\r\n`waitForNetworkIdle(500)` function returns promise which gets resolved when network was idle for passed time (in this example 500 ms)\r\n\r\nTo avoid race condition, please use below syntax.\r\n\r\n```\r\nawait Promise.all([       \r\n    puppeteerPendingRequests.waitForNetworkIdle(500),\r\n    await this.someElement.click()\r\n]);\r\n```\r\n\r\n## Example\r\n### Example 1\r\nLets say there are two xhr requests happen when we click on a button, 1st request happens as soon as we click on button and 2nd request happens after 200 milliseconds after receiving 1st requests response.\r\n\r\n```\r\n1req------|\r\n           ----200ms----|\r\n                        2req--------|\r\n                                     ----250ms (network idle)-----\r\n                                \r\n\r\n```\r\n\r\nWe want our function to wait for both requests to finish.\r\n\r\nWe will call our function with time more than 200 (lets say 250) so that we will wait for both requests to finish\r\n\r\n```\r\nawait Promise.all([       \r\n    puppeteerPendingRequests.waitForNetworkIdle(250),\r\n    await this.button.click()\r\n]);\r\n```\r\n\r\n### Example 2\r\nLets say there are three xhr requests happen simultaneously when we click on a button.\r\n\r\n```\r\n1req------|\r\n2req---------------|\r\n3req---|\r\n                    ------100 ms (network idle) -----\r\n```\r\n\r\nWe want our function to wait for all requests to finish.\r\n\r\nWe will call our function with time more than 0 (lets say 100 default). Since we all requests happening at the same time, time does not matter. Function will wait untill all requests finish.\r\n\r\n```\r\nawait Promise.all([       \r\n    puppeteerPendingRequests.waitForNetworkIdle(100),\r\n    await this.button.click()\r\n]);\r\n```\r\n\r\n## Documentation\r\n\r\n### `PuppeteerPendingRequests`\r\nConstructor function takes puppeterr page as paramter and returns instance\r\n\r\n**Params**\r\n| Name | Type | Default |  Description |\r\n| --- | --- | --- | --- |\r\n| page | Puppeteer Page Object |  | |\r\n\r\n**Returns**\r\n\r\nPuppeteerPendingRequests instance\r\n\r\n### `waitForNetworkIdle`\r\nWait for network to be idle for said time\r\n\r\n**Params**\r\n| Name | Type | Default |  Description |\r\n| --- | --- | --- | --- |\r\n| time | `number` | 100 | This will make function to wait for network to be idle for 100ms |\r\n| resourceType | `string` | `'xhr'` | Resource type to wait for\r\n\r\n**Returns**\r\n\r\nPromise which will get resolved when there is network idle for passed time for specific resource type","readmeFilename":"README.md"}