title: How to pass a function in Puppeteers .evaluate() method
body: <p>Whenever I try to pass a function, like this:</p>
  
  <pre><code>var myFunc = function() { console.log("lol"); };
  
  await page.evaluate(func =&gt; {
   func();
   return true;
  }, myFunc);
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>(node:13108) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: TypeError: func is not a function
  at func (&lt;anonymous&gt;:9:9)
  (node:13108) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <p>Why? How to do it correctly?</p>
  
  <p>Thank you!</p>
  
  <p>€: let me clarify: I am doing it this way because I want to find some DOM elements first and use them inside of that function, more like this (simplified):</p>
  
  <pre><code>var myFunc = function(element) { element.innerHTML = "baz" };
  
  await page.evaluate(func =&gt; {
    var foo = document.querySelector('.bar');
    func(foo);
    return true;
  }, myFunc);
  </code></pre>