title: How to find element id using click event listener in puppeteer
body: <p>I am using puppeteer to listen to click events. I would also like to know the id of the html element clicked. How can I do so? My code right now is as follows:</p>
  <pre><code>const puppeteer = require('puppeteer');
  const fs = require('fs');
  
  (async () =&gt; {
  let browser = await puppeteer.launch({ headless: false });
  let page = await browser.newPage();
  // Expose a handler to the page
    await page.exposeFunction('onClick', ({ type, detail }) =&gt; {
      console.log(`Event fired: ${type}, detail: ${detail}`);
  });
  
  // listen for events of type 'status' and
  // pass 'type' and 'detail' attributes to our exposed function
  await page.evaluateOnNewDocument(() =&gt; {
      window.addEventListener('click', ({ type, detail }) =&gt; {
          window.onClick({ type, detail });
      });
  });
  
  await page.goto(&quot;https://www.facebook.com/login&quot;);
  
  })();
  </code></pre>