As far as I understand you need to block message boxes like alert(), or confirm() to make sure that they'll not stuck your scripts. If yes, what can I suggest is to render (execute) following script in your hidden browser:
alert = function(){};
confirm = function(){};
Works perfectly for me in chrome, firefox, and doesn't work in IE.