title: How to save a canvas as an image using puppeteer?
body: <p>I'm trying to load a page with a canvas and then save it as an image.</p>
  <p>For example, <a href="https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_canvas_tut_path2" rel="nofollow noreferrer">this page</a>. On Chrome, I can right click the canvas with a circle on the upper right side of the page and click save image. I want to do this exact same thing but through NodeJS and Puppeteer. Is this possible?</p>
  <p>So far I'm trying to select it via</p>
  <pre><code>const express = require('express')
  const router = express.Router()
  const puppeteer = require('puppeteer')
  const { Cluster } = require('puppeteer-cluster')
  
  (async () =&gt; {
      
      const cluster = await Cluster.launch({
          concurrency: Cluster.CONCURRENCY_PAGE,
          maxConcurrency: 2,
      })
      
      function sleep(ms) {
        return new Promise(resolve =&gt; setTimeout(resolve, ms));
      }
      
      await cluster.task(async({ page, data: url }) =&gt; {
          // let starmapId = 'celestial-canvas'
  
          await page.goto(url)
          const canvas = await page.evaluate(() =&gt; document.querySelector('#myCanvas'))
          return canvas  // .toDataURL()
      })
      
      router.get('/export/canvas', function(req, res) {
          
          // Get URL
          var url = 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_canvas_tut_path2'
          
          cluster.execute(url).then( canvas =&gt; {
              console.log(canvas)
              res.send(canvas)
          })
      })
      
  })();
  
  module.exports = router
  </code></pre>
  <p>But canvas is returning null.</p>