jonleighton/poltergeist — Issue #19: Client/server get out of sync if when multiple page load events occur
Author: bwbuchanan
Created: 2012-02-09 08:18:37+00:00
State: open

There's a bug in one the ad hoc state machine in browser.coffee that can cause the client and server to get out of sync when multiple page load events happen in response to a click (this probably happens when the server redirects to another URL).

What's happening is that in this case the server sends an additional, spurious "success" response, and the client interprets this as the response to the last command it issued. In my case, it was being interpreted as the response to a "find" command, which led to some very confusing errors!

For the benefit of anyone searching for this, the Ruby error was:

undefined method `map' for "success":String (NoMethodError)

I had some serious bug deja vu when I finally tracked this down. It's basically the same bug as capybara-webkit issue 39 ( https://github.com/thoughtbot/capybara-webkit/issues/39 ).

I made a one-line workaround for this: https://github.com/bwbuchanan/poltergeist/commit/ce13a75801fe7d49b14276e9041b5b63446f4f79

But the real solution is to build a robust state machine around page loading. Ideally, it would handle the case where a redirect happens by waiting until the final page load completes before returning success to the client. This maybe means waiting for a few msec after receiving the onPageLoaded event to see if webkit immediately sends a new onPageLoading event.