[Greasemonkey] GM_log

Prakash Kailasa pk-moz at kailasa.net
Fri Jul 1 12:53:09 EDT 2005


On Fri, Jul 01, 2005 at 11:32:03AM +0930, Shaun Etherton wrote:
> Hi,
> 
> I have just started looking at greasemonkey so I'm sorry if this is a
> dumb question.
> I was wondering if its possible to use GM_log from within non user.js
> javascript files somehow.
> 
> I have been asked to add some functionality to a complex Javascript
> application and was hoping to use this instead of alerts for debugging.


Sometimes, I redefine alert when I have a lot of debugging output
on a page:

alert = function(s) { 
    var ta = document.getElementById('debug');
    if (!ta) {
	var ta = document.createElement('textarea');
	ta.id = 'debug';
	ta.rows = 8; ta.cols = 80;
	document.body.appendChild(ta);
    }
    ta.value += s+'\n';
}

This creates a textarea on the same page where the debug info is written.

All your debug output is together instead of being combined with all
other log messages in the JS console. On the other hand, you might
prefer to log to the console and not clutter up your page. Different
tools for different situations.

This, however, doesn't work with IE, since it doesn't let you redefine
alert function, but that might or might not be a concern for you.

[I found this tip on Stuart Langridge's blog (http://kryogenix.org)]

/prakash

-- 
|"I'd crawl over an acre of 'Visual This++' and 'Integrated            |
|Development That' to get to gcc, Emacs, and gdb.  Thank you."         |
|(By Vance Petree, Virginia Power)                                     |


More information about the Greasemonkey mailing list