@required scripts without final semicolon cause problems #1491

FinnE opened this Issue Jan 3, 2012 · 6 comments


None yet

3 participants

FinnE commented Jan 3, 2012

Greasemonkey 0.9.13 on Firefox 8.0.1.


It appears that @required scripts that do not end in a semicolon can cause problems in the user script.

Steps to reproduce:

  1. Create a new user script which @includes *.
  2. @require the minified jQuery and jQuery-UI 1.8.17 (in that order) from Google APIs (http://code.google.com/apis/libraries/devguide.html#jquery).
  3. Put an alert call inside an anonymous wrapper function in the user script, e.g.: (function(){alert("Hello")})();
  4. Install and run the script.

Expected result:

  • Alert is called, producing a dialogue box.

Actual result:

  • Nothing happens.


  • Add a semicolon to the start of the user script.


While not hard to work around, the problem is hard to identify, as it produces no errors or obvious side effects (besides the user script doing nothing).

jerone commented Jan 3, 2012

You can use GitHub Gist to create an example UserScript.


Can't reproduce. https://gist.github.com/1677686

Installs and runs both requires, none of the 3 files have a semicolon in them. So it's not just semicolons. It's something else about the contents of those two URLs, as the link you posted (on the 4th) definitely does exhibit some weird behavior. Except your description isn't perfectly correct. There's not "no effect". I see, in the error console:

Error: function (a, b) {...severely truncated...}(jQuery) is not a function
Source file: file:///.../gm_scripts/RequireExample/RequireExample.user.js
Line: 10

I also see everything work correctly when I remove the anonymous function wrapper. So: the real cause is that the statement that jquery-ui runs has a return value. The first non-whitespace non-comment character in your script is an open parenthesis, which javascript interprets in this context as a function call to the return value of the still-open statement (semicolon insertion logic fail!).

Since it should be universally safe to append semicolons to working requires, I think we'll just do that, to address this class of failure.


FYI: http://inimino.org/~inimino/blog/javascript_semicolons

Firstly, a semicolon is optional only where there is a line break, a closing brace, or the end of the program. Semicolons are not optional between statements appearing on the same line. Additionally, a semicolon is not implied at the end of a line if the first token of the subsequent line can be parsed as part of the same statement.

(Emphasis mine.) So, in this particular case, where there was only whitespace then an open paren, this is valid syntax, so the semicolon is not inserted. But it's not a valid value to be calling as a function, so the result is a runtime error.

@arantius arantius closed this in 68da160 Jan 25, 2012

Reporters: Please test and report whether this build fixes your issues:

FinnE commented Jan 26, 2012

Confirmed that 0.9.15 fixes the issue.

I do wonder why I didn't get any errors in my console though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment