cuprite
cuprite copied to clipboard
compatibility with Emulation.setVirtualTimePolicy
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?
Could you attach FERRUM_DEBUG logs as well?
sure! https://gist.github.com/dreyks/ab4493c24f66d78944c789f970343bf8
There's no Page.frameStoppedLoading event signaling that frame is loaded. Could you try same without setVirtualTimePolicy and check if this event appears?
yup, it does appear https://gist.github.com/dreyks/9826a7a42277798606056daa5b135121
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?
so is the issue in that chrome doesn't send Page.frameStoppedLoading when the timer is emulated?
@dreyks yes exactly
ok, thx, I'll do that. let's keep the issue open, I'll post the link to a ticket when i make one
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 :(