Robustly handle phantomjs callbacks. Fixes #140