Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uglified code breaks Greasemonkey scripts #583

Closed
Martii opened this issue Nov 21, 2014 · 4 comments
Closed

Uglified code breaks Greasemonkey scripts #583

Martii opened this issue Nov 21, 2014 · 4 comments

Comments

@Martii
Copy link
Contributor

Martii commented Nov 21, 2014

When using express-minify 0.1.1 which currently uses a dependency of uglify-js 2.4.15 we are currently experiencing a breakage during minification.

Current passed through uglify-js options used are:

res._uglifyOutput = {
  comments: true,
  beautify: false
};

res._uglifyMangle = false;

Reduced testcase at https://gist.github.com/Martii/2f032c172d438435aef7 with minified output results attached.

Currently GM, and variants, requires that the first UserScript metadata block comment starts on its own line with no whitespace save for the prior newline in the text stream... uglify-js appears to be stripping the newline out with the above options and thus breaks the UserScript metadata block and script injection occurs everywhere instead of what the author intends.

Any assistance would be greatly appreciated.

See also:

@avdg
Copy link
Contributor

avdg commented Jan 8, 2015

I guess this issue can be generalized "line starting with comments" - and only that - (so drop the see also thingy, userscripts - except that comments have to start on its own line and related github issues).


If the generator can detect that a comment started from pos 0, I think it should be possible to put that comment on a separate line.

Though then there are the comments starting with whitespace characters. I currently don't know how to deal with that (even though this may be not impossible?).

@Martii
Copy link
Contributor Author

Martii commented Jan 29, 2015

@rvanvelzen and Cc: @avdg
I just retested this on our dev environment and it's still serving:

!function(){// ==UserScript==
// @name          RFC 2606§3 - Hello, World!
// @namespace     http://localhost.localdomain
// @description   JavaScript alert box saying Hello, World!
// @copyright     2007+, Marti Martz (http://userscripts.org/users/37004)
// @license       GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @license       (CC); http://creativecommons.org/licenses/by-nc-sa/3.0/
// @version       0.0.0
// @icon          https://s3.amazonaws.com/uso_ss/icon/13701/large.png
// @homepageURL   https://github.com/Martii/UserScripts/tree/master/src/RFC%202606%C2%A73/Hello%2C%20World
// @homepageURL   https://openuserjs.org/scripts/Marti/RFC_2606%C2%A73_-_Hello,_World!
// @homepageURL   http://userscripts.org/scripts/show/13701
// @supportURL    http://userscripts.org/topics/23566
// @include   http://www.example.com/*
// @include   http://www.example.net/*
// @include   http://www.example.org/*
// ==/UserScript==
alert("Hello, World!")}();

... !function(){// ==UserScript== isn't keeping the line break that was put in.

Thanks for trying though... @rvanvelzen can this be reopened or do you want me to create a new issue with the exact same criteria referencing this one?


EDIT: Oh wait ... did you publish this to npmjs.com?

@rvanvelzen
Copy link
Collaborator

Sorry, this hasn't been in a release yet. HEAD gives the correct result.

@Martii
Copy link
Contributor Author

Martii commented Jan 29, 2015

Aww kewl... just got done retesting it with a manual patch into express-minify deps and it works (even with tab characters)... learned something about our project too that slightly deviates from the GM standard but minimal... retested on the known 99% observations that I've seen people trying to hack GM_info and appears to keep all comments starting at the beginning of the line in the UserScript metadata block. Thank you both and sorry for the extra noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants