title: Puppeteer : script seems to go iddle
body: <p>I am currently working on a script that takes screenshots of every individual div inside of a page.
  The script works but is getting slower after each iteration. For example, the 11th iteration takes several minutes, while the first takes only but a few seconds. Also, the script never actually stops with an error, I believe it will run forever if I don't interrupt it.</p>
  <p>Did any of you guys ever went through the same issue ? Is there a way to solve this problem ? I am new to promises and Puppeteer...</p>
  <p>Thanks in advance !</p>
  <p>Below is the code of my function and the execution output.</p>
  <p>Here is the code of the function :</p>
  <pre><code>async function takeScreenshot(bookPage){
      await bookPage.evaluate(() =&gt; {
          document.body.style.position = &quot;relative&quot;;
          document.querySelector(&quot;#page-container&quot;).style.position = &quot;relative&quot;;
       });
  
      for(var i = 0; i &lt; allPagesDimensions.length; i++){
          console.log(&quot;Itération n°&quot; + i);
  
          await bookPage.evaluate((i) =&gt; {
              const page = document.querySelector(&quot;#pf&quot; + (i + 1));
              window.scrollTo(0, page.offsetTop);
          }, i);
  
          const pageDimensions = await bookPage.evaluate((i) =&gt; {
              const page = document.querySelector(&quot;#pf&quot; + (i + 1));
              var returnValue = { x: page.offsetLeft, y: page.offsetTop, width: page.clientWidth, height: page.clientHeight };
              return returnValue;
          }, i);
  
          console.log(&quot;Lancement de la capture&quot;);
          await bookPage.screenshot({
                  path: &quot;page-&quot; + i + &quot;.png&quot;,
                  clip: { &quot;x&quot;: pageDimensions.x, &quot;y&quot;: pageDimensions.y, &quot;width&quot;: pageDimensions.width, &quot;height&quot;: pageDimensions.height }
          });
          console.log(&quot;Capture réussie&quot;);
      }
  }
  </code></pre>
  <p>And the output is the following :</p>
  <pre><code>Itération n°0
  Lancement de la capture
  Capture réussie
  Itération n°1
  Lancement de la capture
  Capture réussie
  Itération n°2
  Lancement de la capture
  Capture réussie
  Itération n°3
  Lancement de la capture
  Capture réussie
  Itération n°4
  Lancement de la capture
  Capture réussie
  Itération n°5
  Lancement de la capture
  Capture réussie
  Itération n°6
  Lancement de la capture
  Capture réussie
  Itération n°7
  Lancement de la capture
  Capture réussie
  Itération n°8
  Lancement de la capture
  Capture réussie
  Itération n°9
  Lancement de la capture
  Capture réussie
  Itération n°10
  Lancement de la capture
  Capture réussie
  Itération n°11
  </code></pre>