jQuery Sandbox Conflict in Greasemonkey 1.0:
With the introduction of Greasemonkey 1.0, the sandbox mechanism has undergone significant changes, resulting in conflicts between jQuery versions on websites using the platform and Greasemonkey scripts.
The conflict arises due to the new @grant code, which modifies the sandbox behavior. This has led to scripts relying on jQuery in the @require metadata malfunctioning due to interference from the page's own jQuery instance.
Resolving the Conflict:
Greasemonkey's official documentation suggests a workaround involving this.$ = this.jQuery = jQuery.noConflict(true). However, this solution may not work effectively in all cases and can compromise coding principles.
A more optimal solution involves re-implementing the sandbox mechanism. This can be achieved by specifying a @grant value (other than none) in the metadata block of the Greasemonkey script.
Example Metadata Block:
// @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. */
By restoring the sandbox, conflicts between different jQuery instances are resolved, and scripts regain their compatibility with superior engines such as Tampermonkey and Violentmonkey.
The above is the detailed content of How Do I Resolve jQuery Sandbox Conflicts in Greasemonkey 1.0?. For more information, please follow other related articles on the PHP Chinese website!