merged latest changes from steeve's repo, using window.callPhantom to invoke callback instead of firing an event