This thread is trying to answer question "Is it possible to pass functions into $$eval in Playwright?"
I think the $$eval is from ElementHandle which is deprecated. Playwright encourages to use Locator instead. https://playwright.dev/docs/api/class-elementhandle
Indeed, it's better to use Locator. Using element handles is discouraged. Element handles are much less stable/less flake resistant.
So instead of page.$$eval, this is the better option: https://playwright.dev/docs/api/class-locator#locator-evaluate-all
Passing functions like this from NodeJS execution context to the browser execution context does not work. What we pass as arguments needs to be serializable.
If you want to have functions in the browser execution context which call code in the NodeJS execution context, then you can use this: https://playwright.dev/docs/api/class-page#page-expose-function
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email firstname.lastname@example.org.