problem with @grant and jquery

in Script development
Subscribe to problem with @grant and jquery 3 posts, 3 voices



RASG Scriptwright
FirefoxWindows

Since GM version 1.0 , all my scripts that @require jquery, running on sites that also uses jquery stopped working.

I know, i could try something like $ = unsafeWindow.$ , but that is not the point.

The point here is that they used to work, and now they wont.

So i thought it could be related to the new security model, and added @grant GM_log.

Now they work as they should!

The "automatic" mode, where GM tries to guess if you need the sandbox (for backward compatibility) is not working properly.

Anyone else having issues like mine?

 
Jefferson Scher Scriptwright
FirefoxWindows

Yes. See: "@grant none" (or auto-detected none) combined with JQuery == Bad News · Issue #1614 · greasemonkey/greasemonkey · GitHub. But I can't tell from that thread what approach has been chosen going forward.

 
Cletus Scriptwright
FirefoxWindows

See the post on Greasespot, Greasemonkey 1.0 + jQuery: Broken, with Workaround.

Basically, insert this at the top of your script (not in any function, and just below the meta block):

this.$ = this.jQuery = jQuery.noConflict(true);

Read that post for some more info as to why this is happening.

As for the auto-detection of the sandbox, you must actually use a GM_* function for it to detect it. It is recommended that you specify @grant directives instead of relying on the auto-detection--who knows how long auto-detection will be in GM.