views:

544

answers:

1

I want to do some browser automation, and those pesky confirm/alert boxes are a real pain. Disabling javascript completely in this case is not an option, unfortunately.

Well, so I was wondering, can I just change the definition of those methods as seen by my browser's javascript interpreter to basically do nothing and return true? Note that I do know about redefining them in the Javascript code directly, e.g. putting in

function alert(message)
{
  return true;
}

but AFAIK this is not a viable approach for this situation because when doing browser automation I have to work with other people's Javascript. Moreover, my program actually begins manipulating these websites already after the page has fully loaded into the browser, so I cannot just first automatically rewrite the javascript and then load the page. Well, so I was wondering if I could instead just "permanently" modify the way alert/confirm are implemented and executed in my browser. Sort of like the equivalent of dll injection and so forth in the realm of windows apps.

+1  A: 

Yes it can be done. Try this thread

Anil Namde
I have already mentioned this approach in my original post. It doesn't work because I am not the guy running the server and I cannot insert new code into the Javascript files from the server. I am the guy doing browser automation, and my browser ends up loading whatever javascript provided by the website.
EndangeringSpecies