title: Get all links with XPath in Puppeteer (pausing or not working)?
body: <p>I am required to use XPaths to select all links on a page, for then my Puppeteer app to click into and perform some actions. I am finding that the method (code below) is getting stuck sometimes and my crawler will be paused. Is there a better/different way of getting all links from an XPath? Or is there something in my code that is incorrect and could be pausing my app's progress?</p>
  
  <pre><code>try {
    links = await this.getLinksFromXPathSelector(state);
  } catch (e) {
    console.log("error getting links");
    return {...state, error: e};
  }
  </code></pre>
  
  <p>Which calls:</p>
  
  <pre><code>async getLinksFromXPathSelector(state) {
   const newPage = state.page
   // console.log('links selector');
   const links = await newPage.evaluate((mySelector) =&gt; {
     let results = [];
     let query = document.evaluate(mySelector,
       document,
       null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
     for (let i=0, length=query.snapshotLength; i&lt;length; ++i) {
       results.push(query.snapshotItem(i).href);
     }
     return results;
   }, state.linksSelector);
    return links;
  }
  </code></pre>
  
  <p>The XPath is in <code>state.linksSelector</code>.</p>