-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
page.evaluate returns empty object #32864
Comments
Ok I worked it around by using global object at the browser side and then requesting the property of a global object later as follows:
|
Hi! You ran into the behaviour that's documented here: https://playwright.dev/docs/api/class-page#page-evaluate
Instead of storing your // ...
const config = await page.evaluateHandle(() => {
// ...
return config;
});
// ...
const hasDropdownFlashed = await page.evaluate(config => {
config.observer.disconnect();
return config.hasDropdownFlashed;
}, config);
// ... Let me know if that helps! |
Hi @Skn0tt , thank you for quick response! I have just tried your suggestion and I got the error |
Hmm, unsure why that happens. I don't have access to your full code so I can't make sure that my snippet works. This example works for me: import { test } from "@playwright/test";
test("repro", async ({ page }) => {
await page.goto("https://example.com");
const config = await page.evaluateHandle(() => {
const observer = new MutationObserver(() => {});
const config = { observer }
return config;
})
await page.evaluate(config => {
config.observer.disconnect();
}, config);
}) If you're getting |
Yes you are right! I double checked the code and I noticed that first time I did not use |
That's wonderful to hear! Closing then 😁 |
Hi there,
I am trying to return a class instance or a function from page.evaluate and it returns either an empty object or
undefined
. Here are some examples:The idea is to check whether a dialog flashes for some milliseconds while a users types the text. For that I setup a MutationObserver. As a result of
page.evaluate
I would like to get access tohasDropdownFlashed
andobserver
to disconnect the observer.However as I can see the returned instance of Observer is replaced with an empty object.
Is there any way to achieve what I explained? Thank you!
The text was updated successfully, but these errors were encountered: