title: Puppeteer wait for url
body: <p>I have headless off and I want to wait untill user redirect to some page. I could use <code>waitForRequest</code> from puppeteer API but I don't know exact url it just must pass few circumstances.</p>
  
  <p>So I use waitForFunction and check circumstances there but when I redirect to correct URL then I need to refresh page to pass circumstances for some reason.</p>
  
  <p>My code is:</p>
  
  <pre><code>try {
      await page.waitForFunction(() =&gt; {
          if(window &amp;&amp;
             window.location &amp;&amp;
             window.location.hostname) {
              const host = window.location.hostname.split('.');
              if(!host.includes('www') &amp;&amp;
                 !host.includes('new') &amp;&amp;
                 host.includes('margonem') &amp;&amp;
                 host.length === 3) {
                  return true;
              }
          }
      }, {
          polling: 200,
          timeout: 0
      })
  } catch (e) {
      console.log(e);
  }
  </code></pre>
  
  <p>and when I redirect to URL which pass all of above if's then I need to reload page to actually see that it return true. Why it works like this? I don't want user to be forced to refresh page after he enter correct one.</p>