I am trying to get mutation observer working in puppeteer. When I log the mutations array I just get an empty object in array like [{}]
Here is my code:
await page.exposeFunction("puppeteerLogMutation", (mutations) => {
console.log(mutations);
});
await page.evaluate(() => {
const target = document.querySelector("#SHORTCUT_FOCUSABLE_DIV");
const observer = new MutationObserver((mutations) => {
puppeteerLogMutation(JSON.stringify(mutations));
});
observer.observe(target, { childList: true });
});
Other answers I see online say that I need serialize the mutations array into a string before I pass it back into puppeteer with the puppeteerLogMutation
function. and I am doing that, but it's still empty data. What would be the best way, to get the entire element that gets added to the dom, as well as the other elements in that element? JSON.parse()
doesn't do anything, and mutations.toString()
just returns [object Object]
If anyone could help, I would really appreciate it! Thanks!