title: How to speed up puppeteer?
body: <p>A web page has a button and puppeteer must click that button as soon as possible button becomes visible. This button is not always visible and it is becoming visible for everyone at the same time. So i have to refresh constantly to find that button is became visible. I wrote that script below for to do that:</p>
  <pre><code>    const browser = await puppeteer.launch({
          headless: true,
          args: ['--no-sandbox']
      });
      const page = await browser.newPage()
      await page.setViewport({ width: 1920, height: 1080})
  
  
  //I am calling my pageRefresher method here
  
  async function pageRefresher(page,browser, url) {
          try {
              await page.goto(url, {waitUntil: 'networkidle2'})
              try {
                  await page.waitForSelector('#ourButton', {timeout: 10});
                  await page.click('#ourButton')
                  console.log(`clicked!`)
                  await browser.close()
              } catch (error) {
                  console.log('catch2 ' + counter + ' '  + error)
                  counter += 1
                  await pageRefresher(page, browser, url)
              }
          }catch (error) {
              console.log('catch3' + error)
              await browser.close();
          }
  }
  </code></pre>
  <p>As you can see, my method is recursive. It goes to that page and looking for that button. If there is no button then it calls itself again for redoing the same job until it finds and clicks to that button.</p>
  <p>Actually it works well right now. But it is slow. I am running this script meanwhile i am opening the same page on my desktop chrome and i am starting to refresh that page manually. And i am always winning, i am always clicking to that button before the puppeteer.</p>
  <p>How can i speed up this process? A script should not lose to a human who has just manual controls like F5 button.</p>