Welcome to MTurk Crowd

Work on Amazon Mechanical Turk, learn from the best, and have fun doing it. Join the crowd today!

Sign Up

JQuery Conflict-Prevention - Scripting Safety/Compatibility PSA

Discussion in 'Userscripts, Extensions, and Software' started by clickhappier, Jan 18, 2016.

Thread Status:
Not open for further replies.
  1. clickhappier

    Expand Collapse
    ┬──┬ ノ( ゜-゜ノ)

    • Subforum Curator
    • Crowd Pleaser
    Jan 12, 2016
    I've been telling script-writing people about this repeatedly since back in 2014...

    JQuery is fantastic for making userscripts easier to read and write (simplifying some things that are overly convoluted in standard Javascript). Just take this easy precaution:

    If you use JQuery in a userscript that runs on any webpage/site that uses JQuery for its own functions, your script will break features of that page/site in Firefox, unless you take precautions. The simplest way to do this is to declare an @grant value other than 'none' ('none' is the default if you didn't declare any) - I recommend declaring @grant GM_log .

    Here's a random before and after example of the change - just modifying or adding that one @grant line.

    You can use @grant-triggered sandbox mode in pretty much all your scripts, whether or not they use JQuery and whether or not they run on a site that uses JQuery, to get and stay in the habit of having that precaution in place. Other sites might decide to start using JQuery in the future, too. So put it in your template for future scripts (and seriously, try to go through and fix your old ones even if you're not using them currently, since you or someone else might base a future script off of copying from it even if you never use that particular one again), so you don't keep forgetting!

    This is critical for JQuery-using scripts running on the following sites (among others) commonly used by turkers: (I know more of you have your own private requester-specific scripts that run on one or more of these too!)
    • * (which means all sites... and any userscript without an @include or @match line is running on * too, btw... will break all of the below sites, and many others outside turkdom including social media, news, etc)
    • mturkcontent.com (used by tons of requesters, some of whom use JQuery)
    • s3.amazonaws.com (used by quite a few requesters, some of whom use JQuery)
    • can happen for some requesters who use their own requester-specific domains too; and I suspect some of the fancier Qualtrics interfaces might be affected as well
    • Xenforo-based forums, including mturkcrowd.com and (since Jan 2015) mturkgrind.com
    • turkopticon.ucsd.edu

    The reason for this behavior is: Chrome's userscript-running extension Tampermonkey runs userscripts in 'sandbox mode' all the time, which reduces the chance of problematic interactions like this with the original page's content. But Firefox's userscript-running extension Greasemonkey only uses 'sandbox mode' when a non-null @grant is declared. This is because Greasemonkey, the original userscript engine that started it all in March 2005, has been around much longer than Tampermonkey (circa 2010) and wanted to maintain backwards compatibility with the rare scripts that do some obscure things that aren't readily achievable in sandbox mode. Unfortunately the way the GM devs implemented this a few years ago was very controversial due to it causing negative impacts like this in vastly more cases than the opposite. But it is what it is at this point, and this is a simple fix... if people would be better about actually using it in their scripts. :p
    rosesword975 and Tribune like this.
Thread Status:
Not open for further replies.