I am using puppeteer to perform some tests on a rendered page.
One of the tests it to click every element on the page and then measure the document body to see if any of the elements have resize events attached to them.
The problem is that if an element is a link to another page, puppeteer navigates away (as expected). I want to prevent this behaviour.
I have tried to use setInterceptionRequest but I get an error on doing so. Included is the relevant parts of my code and the error.
Can anyone advise the best way to accomplish this?
const browser = await puppeteer.getBrowser();
const page = await browser.newPage();
await page.setContent(html);
await page.setRequestInterception(true);
page.on('request', request => {
if (request.resourceType() === 'document') {
request.abort();
} else {
request.continue();
}
});
let elements = await page.$$('body *');
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
await element.click()
}
Error: Protocol error (Runtime.callFunctionOn): Argument should belong to the same JavaScript world as target object