How to debug Greasemonkey script with the Firebug extension?

Viewed 43815

I didn't find a way to debug Greasemonkey scripts with the Firebug extension.

Does anyone know how to do this ?

Thanks.

10 Answers

Similar to @bigml's suggestion, you can run it unprivileged if you setup a local webserver (apache) to serve the userscript file, then in your userscript add something along the lines:

if (typeof GM_addStyle == "undefined") {
    loadScript("http://localhost/path/to/script.user.js");
}
else {
    runScript();
}

function loadScript(url) {
     var script = document.createElement('script');
     script.type = 'text/javascript';
     script.src = url;
     document.getElementsByTagName('head')[0].appendChild(res);
}

function runScript() {
     // ... whatever your userscript does ...
}

Of course you wouldn't be running in a privileged context. But this way you can easily continuously debug the script as any other script.

Related