Listen to the onbeforeunload event

13 views
Skip to first unread message

Ariel Juodziukynas

unread,
Oct 19, 2021, 4:10:41 PM10/19/21
to Capybara
I'm doing research on taking code coverage metrics for the JS code using Istanbul. Currently, what I'm doing is using a before_teardown hook to read the `window.__coverage__` object and store the result in a file to process it later.

This is not ideal because there are some use cases I will miss, for example:
- a form submission that changes/refreshes the page
- a link that takes the user to a different page
- a call to `visit` during the flow of a test

So I was thinking if there's any way to attach a callback to the onbeforeunload event so I can always extract that info from the browser for any page change. Ideally, I would add some kind of listener that will run ruby (or maybe even javascript?) code.

I'm not sure if something like that is even possible, I understand capybara can control the browsers with specific drivers but I don't know if it can use the drivers to listen to events too.

Thanks!
Reply all
Reply to author
Forward
0 new messages