title: How to get body / json response from XHR request with Puppeteer
body: <p>I want to get the JSON data from a website I'm scraping with Puppeteer, but I can't figure how to get the body of the request back. Here's what I've tried:</p>
  
  <pre><code>const puppeteer = require('puppeteer')
  const results = [];
  (async () =&gt; {
      const browser = await puppeteer.launch({
          headless: false
      })
      const page = await browser.newPage()
      await page.goto("https://capuk.org/i-want-help/courses/cap-money-course/introduction", {
          waitUntil: 'networkidle2'
      });
  
      await page.type('#search-form &gt; input[type="text"]', 'bd14ew')  
      await page.click('#search-form &gt; input[type="submit"]')
  
      await page.on('response', response =&gt; {    
          if (response.url() == "https://capuk.org/ajax_search/capmoneycourses"){
              console.log('XHR response received'); 
              console.log(response.json()); 
          } 
      }); 
  })()
  </code></pre>
  
  <p>This just returns a promise pending function. Any help would be great.</p>