playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
1.94k stars 144 forks source link

Page.Evaluate returns undefined for a specific site #417

Closed reginaldl closed 4 months ago

reginaldl commented 4 months ago

Hi,

I'm calling Page.Evaluate while browsing a specific site and it consistently returns nil (no error though). Here's the debug traces:

SEND>
{"guid":"frame@77e4062f9cb0cdcd0f9aeb454d7a1983","id":45,"metadata":{"apiName":"SerializeCallStack","isInternal":false,"location":{"file":"connection.go","line":162},"wallTime":78307000},"method":"evaluateExpression","params":{"arg":{"handles":[],"value":{"n":42}},"expression":"l =\u003e String(l)"}}
RECV>
{"id":45,"guid":"","result":{"value":{"v":"undefined"}}}

Any JS would return undefined. The site is starpets.gg. It reproduces with all browsers. Is there any reason why evaluate would not fail but yet return undefined? If this is a playwright bug, what's the best way to report it coming from playwright-go?

Thanks!

canstand commented 4 months ago

can't reproduce via: https://github.com/canstand/playwright-go/commit/4b2c84cfb7c4dc2dd8473e0a80fa025476700a2d

reginaldl commented 4 months ago

can't reproduce via: canstand@4b2c84c

Oh interesting, so it turns out that it returns nil exclusively when using playwright.WaitUntilStateNetworkidle.

Updating the following line should repro:

 _, err = page.Goto("https://starpets.gg", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateNetworkidle})
canstand commented 4 months ago

networkidle DISCOURAGED

reginaldl commented 4 months ago

Thanks for your detailed answer. Networkidle is discouraged, for tests, because it relies on sleeps (500ms). Most time based expectations are an anti-pattern in testing, hence the "DISCOURAGED". However it doesn't explain why page.evaluate would have an unexpected behavior. I ended up filing a bug upstream as I could repro with node: https://github.com/microsoft/playwright/issues/29440