cuprite icon indicating copy to clipboard operation
cuprite copied to clipboard

compatibility with Emulation.setVirtualTimePolicy

Open dreyks opened this issue 1 year ago • 9 comments

I'm trying to mock time on the frontend, for this I'm mocking time on the backend using ActiveSupport's travel_to and then trying to make it propagate to the browser

travel_to Time.zone.local(2024, 'jan', 1)
page.driver.browser.page.command(
  'Emulation.setVirtualTimePolicy',
  policy: 'pause',
  initialVirtualTime: Time.zone.now.to_i
)
p page.driver.browser.evaluate('(new Date()).toString()')

this does work returning Mon Jan 01 2024 00:00:00 but then i get an error

Ferrum::PendingConnectionsError: Request to http://127.0.0.1:55665/ reached server, but there are still pending connections: http://127.0.0.1:55665/

looks like something doesn't work well with virtual time

according to the docs policy: 'pause' means that browser is not allowed to fast-forward the time when it's out of work if i pass policy: 'advance' ferrum doesn't complain but the time advances too quickly: one visit and it's already the next month

any ideas?

dreyks avatar Apr 24 '24 15:04 dreyks

Could you attach FERRUM_DEBUG logs as well?

route avatar Apr 26 '24 06:04 route

sure! https://gist.github.com/dreyks/ab4493c24f66d78944c789f970343bf8

dreyks avatar Apr 26 '24 08:04 dreyks

There's no Page.frameStoppedLoading event signaling that frame is loaded. Could you try same without setVirtualTimePolicy and check if this event appears?

route avatar Apr 26 '24 10:04 route

yup, it does appear https://gist.github.com/dreyks/9826a7a42277798606056daa5b135121

dreyks avatar Apr 26 '24 11:04 dreyks

Sorry, this convo slipped thru the cracks. I'm afraid it's Chrome's issue then. We should raise an issue like this one https://issues.chromium.org/issues/40923369 though fix is not going to happen quick. Could you please create one?

route avatar May 06 '24 15:05 route

so is the issue in that chrome doesn't send Page.frameStoppedLoading when the timer is emulated?

dreyks avatar May 06 '24 16:05 dreyks

@dreyks yes exactly

route avatar May 06 '24 16:05 route

ok, thx, I'll do that. let's keep the issue open, I'll post the link to a ticket when i make one

dreyks avatar May 06 '24 17:05 dreyks

I linked wrong issue, the updated comment has a link on a better one with better explanation. Bad thing is that it takes them forever to fix anything, so don't expect any real quick fix :(

route avatar May 07 '24 06:05 route