Turn Off Debugging

The JavaScript alert(), confirm() and prompt() calls are intended to be used in modern JavaScript only as debugging tools. Unfortunately there are some people who accidentally leave these calls in their code when they have finished testing and implement it.

It can be rather annoying when debugging calls that someone placed in their JavaScript and forgot to remove result in dialogs displaying as you interact with their page - particularly the ones that don't display the extra checkbox allowing you to turn them off yourself. We can resolve this quite simply by adding a fairly short userscript into our browser that effectively overrides the debugging dialog calls with calls to dummy functions that simply return to the script without displaying a dialog at all. Because there is the possibility that there will be debugging calls in the code that the web page loads in the first place and any executable code in our userscript may not be run until afterwards this is one instance where it is appropriate to use function declarations to override the dialog calls rather than function statements (as is always more appropriate in scripts attached to the web page rather than the browser).

The disable.user.js script just needs to be installed into your particular browser. For Firefox/Greasemonkey simply right click the link and select "Install User Script". With Opera the easiest way is to go into the link and select "Save As" from the "File" menu to save the script into your user script folder. Note that the script is coded so that the dialogs will work when running in a local web server (if you have one) but will be overridden for all sites on the web - if you want to make exceptions you will need to update the include/exclude statements.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow