Update:. For modern versions of Greasemonkey:
You can intercept alert() in most cases using @run-at document-start . For example, download this script, and then visit the test page :
// ==UserScript== // @name Overwrite Alert // @description Overwrites alert() // @include http://output.jsbin.com/* // @grant none // @run-at document-start // ==/UserScript== unsafeWindow.alert=function (str) { console.log ("Greasemonkey intercepted alert: ", str); };
If your script requires GM_ functions , it must set @grant , which is different from none. In this case, use exportFunction() as follows:
// ==UserScript== // @name Overwrite Alert // @description Overwrites alert() // @include http://output.jsbin.com/* // @grant GM_addStyle // @run-at document-start // ==/UserScript== function myAlert (str) { console.log ("Greasemonkey intercepted alert: ", str); } unsafeWindow.alert = exportFunction (myAlert, unsafeWindow);
Old answer, for Greasemonkey until August 2011:
unsafeWindow.alert=function() {}; works great in situations of choice.
But if this is really the code on the page, you cannot stop this warning with Greasemonkey.
This is because this warning will be triggered during page load and before the DOMContentLoaded event that occurs when Greasemonkey is launched.
Download this GM script:
// ==UserScript== // @name Overwrite Alert // @description Overwrites alert() // @include http://jsbin.com/* // ==/UserScript== unsafeWindow.alert=function() {};
Then visit: http://jsbin.com/ajeqe4/6 .
Checking the code ( http://jsbin.com/ajeqe4/6/edit ), you will see 3 warnings. Greasemonkey can stop warnings that fire on load (usually).
Other factors may block GMβs ability to stop the warning ... The page loads too fast or closes, perhaps.
Paste the source of this page, unedited, if at all possible, at pastebin.com. Perhaps something else you can do. Maybe block the script via adblock?
Otherwise, you will need to write an extension / addition.