Skip to content

Is there a way to detect when the visible window is closed by the user? #383

Closed Answered by postmodern
postmodern asked this question in Q&A
Discussion options

You must be logged in to vote

Since every browser.on(...) { ... } block is executed using Concurrent Ruby, one cannot simply call exit as all exceptions are silently rescued within the blocks; and exit raises SystemExit. However, you can use this really simple solution that sets a local variable and busy waits until it's set:

window_closed = false

browser.on('Inspector.detached') do
  window_closed = true
end

until window_closed
  sleep(1)
end

browser.quit
exit

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@route
Comment options

Answer selected by postmodern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants