Puppeteer: pass variable in .evaluate() : <p>I'm trying to pass a variable into a <code>page.evaluate()</code> function in <a href="https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageevaluatepagefunction-args" rel="noreferrer">Puppeteer</a>, but when I use the following very simplified example, the variable <code>evalVar</code> is undefined.</p>

<p>I'm new to Puppeteer and can't find any examples to build on, so I need help passing that variable into the <code>page.evaluate()</code> function so I can use it inside.</p>

<pre><code>const puppeteer = require('puppeteer');

(async() =&gt; {

  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();

  const evalVar = 'WHUT??';

  try {

    await page.goto('https://www.google.com.au');
    await page.waitForSelector('#fbar');
    const links = await page.evaluate((evalVar) =&gt; {

      console.log('evalVar:', evalVar); // appears undefined

      const urls = [];
      hrefs = document.querySelectorAll('#fbar #fsl a');
      hrefs.forEach(function(el) {
        urls.push(el.href);
      });
      return urls;
    })
    console.log('links:', links);

  } catch (err) {

    console.log('ERR:', err.message);

  } finally {

    // browser.close();

  }

})();
</code></pre>
