can I override/redefine "global" Javascript functions, like confirm() and alert()?

Posted by EndangeringSpecies on Stack Overflow See other posts from Stack Overflow or by EndangeringSpecies
Published on 2010-01-22T22:19:43Z Indexed on 2010/06/18 6:03 UTC
Read the original article Hit count: 392

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.

© Stack Overflow or respective owner

Related posts about disable

Related posts about javascript-library