Debug Greasemonkey, get real line numbers

I am trying to get a Greasemonkey handle to work, but it continues to throw "missing, before expression" in the Javascript error console.

Greasemonkey docs say the line number should be ignored, but since the script is quite long, it would be very helpful to know where the error occurred. How can I find out?

Edit: So, a long story. Line numbers are correct in recent versions of Greasemonkey.

+2
source share
1 answer

Recent releases of Greasemonkey seem to adequately report line numbers, but it is best to debug and test as much of your script as possible in the Firebug console before using it in a Greasemonkey script.
And, as has not been said, jsHint can be useful for detecting these problems.

Anyway, suppose I have a script:

// ==UserScript==
// @name        _Debugging test
// @include     http://YOUR_SERVER/YOUR_PATH/*
// ==/UserScript==

unsafeWindow.console.log ('Line 1', 1 + 0);

unsafeWindow.console.log ('Line 2', 1 + 1);

unsafeWindow.console.log ('Line 3', 1 + 2);

unsafeWindow.console.log ('Line 4 **Throw error here**', 1 + 3 + nonExistantVariable);

unsafeWindow.console.log ('Line 5', 1 + 4);


When I run it on 2 of my systems (WinXP, FF: 10.0.2, GM: 0.9.18, Firebug: 1.9.1 and the same except GM: 0.9.17), I get this on the Firebug console:

Line 1 1
Line 2 2
Line 3 3

and this is on the Firefox console Error ( Ctrl Shift J):

Line numbers reported


Clicking on the link gives:

Source Type

There is no true debugging feature, it is not much better.

+1
source

All Articles