I want to create an event listener on every new tab user creates when clicking on any pages, is it possible? this is required to capture user events based on clicks within this new tabs. Like a onClick button event.
I just have test with one page but every other tabs it has no listener on it… this is my code so far.:
const puppeteer = require('puppeteer');
const readline = require('readline');
async function readLine() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
}
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.evaluateOnNewDocument(() => {
window.addEventListener('click', (e) => {
console.log(e.target.getAttribute("id"));
});
});
})();
New contributor
robert pichardo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.