jQuery in Greasemonkey 1.0 conflicts with websites using jQuery

Greasemonkey 1.0, radically changed the way the sandbox works, busting thousands of scripts. This is a huge problem, and I hope you will join me in voicing your opinion/experiences on the principle bug report for this issue.

The Greasemonkey blog claims that you can workaround the issue with the following:

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

… Which I’m not sure will work in all cases. And it is the exact wrong approach from a side-effects-avoiding, DRY-principle, atomic-coding philosophy.   In my opinion, the best strategy is to restore the sandbox.

Reactivate the sandbox by specifying a @grant value (other than none). Edit your Metadata Block to end with the following lines:

// @grant       GM_addStyle
// @grant       GM.getValue
// ==/UserScript==
/*- The @grant directive is needed to work around a design flaws introduced in GM 1.0
    and again in GM 4.0.
    It restores the sandbox.
*/

The sandbox will be restored and all conflicts will be resolved.
And the scripts will be compatible with superior engines like Tampermonkey and Violentmonkey.

Leave a Comment