I am using Playwright in Python, and I want to inject javascript into a page that watches DOM mutations and fires custom events, and catch those events in Python.
This is an example python script:
page.evaluate("//js code that essentially dispatches new CustomEvent('newPosts')")
page.on("newPosts", handle_posts)
So far, nothing happens on Python side, as if events do not exist.
If I manually check browser console, I can see events firing just fine on browser side (which I'm catching with document.addEventListener('newPosts', fn)
I would do this:
evaluate
to register a listener to newPosts
. A Listener on the browser side.