Tampermonkey: cannot require jquery

Created on 16 Mar 2015  路  9Comments  路  Source: Tampermonkey/tampermonkey

What steps will reproduce the problem?
1. add @require    http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js 
to a new script
2. refresh a page
3. inspect page and open javascript console.
4. type jQuery<enter>

What is the expected output? What do you see instead?
Should see something like:
  function (a,b){return new e.fn.init(a,b,h)}
instead see:
  ReferenceError: jQuery is not defined

and this error is appearing in the console:
  ERROR: Execution of script env myScriptName Cannot set property 'innerHTML' of null

What version of the product are you using? On what operating system?
Windows with chrome 17.0.938.0 beta

Original issue reported on code.google.com by [email protected] on 15 Nov 2011 at 1:30

auto-migrated bug

Most helpful comment

The console does not show up a jQuery that is includes by scripts anymore.

By adding a "GM_log(jQuery().jquery);" statement to your script you can can 
check whether jQuery is available.

Another option is to open the console at the page you script will run at and to 
add a "debugger;" statement to the top of your script. If the script execution 
stops at the "debugger;" breakpoint you can test for jQuery's existence.

Original comment by [email protected] on 15 Nov 2011 at 1:45

All 9 comments

The console does not show up a jQuery that is includes by scripts anymore.

By adding a "GM_log(jQuery().jquery);" statement to your script you can can 
check whether jQuery is available.

Another option is to open the console at the page you script will run at and to 
add a "debugger;" statement to the top of your script. If the script execution 
stops at the "debugger;" breakpoint you can test for jQuery's existence.

Original comment by [email protected] on 15 Nov 2011 at 1:45

Tried adding GM_log(jQuery().jquery); and there was nothing in the logs except 
this:
ERROR: Execution of script env Customer Service Collapse failed! Cannot set 
property 'innerHTML' of null

I think it's erroring when it's doing the require for jQuery and not running 
the script.

Original comment by [email protected] on 15 Nov 2011 at 1:52

Hmm, can u please try this script? And btw: you're using TM Beta 2.2.2521, 
right?

// ==UserScript==
// @name           test'em
// @version        1.5.0.1320
// @namespace      http://biniok.net
// @author         _der_
// @run-at         document-start
// @include        http://*/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @resource       icon http://www.imerx.net/favicon.ico
// ==/UserScript==

GM_log("run!");

window.addEventListener("DOMContentLoaded", function() {
    var image = document.createElement('img');
    image.src = GM_getResourceURL('icon');
    document.getElementsByTagName('body')[0].appendChild(image);

    GM_log("done!!");

    GM_log("jQuery().jquery: " + jQuery().jquery);
}, false);

var rrr = function() {
    try {
    GM_log("jQuery().jquery: " + jQuery().jquery);
    GM_log("$().jquery: " + $().jquery);    
    } catch (e) {
        console.log(e);
    }
    // window.setTimeout(rrr, 2000);
};

rrr();

Original comment by [email protected] on 15 Nov 2011 at 2:00

Tried installing beta. I did see your script produce the correct output the 
first page I tried it on. But then it started failing in the same way as the 
stable version.

Original comment by [email protected] on 15 Nov 2011 at 3:17

At what pages does my script fail?

Can you please attach your script or an example that is failing the way your 
script does? At what pages should it run?

Original comment by [email protected] on 15 Nov 2011 at 3:24

Your script fails on pages where the first element is a comment:

http://jsbin.com/axeyok

ERROR: Execution of script env testem failed! Cannot set property 'innerHTML' 
of null

Original comment by [email protected] on 15 Nov 2011 at 4:07

Sorry, but atm I have no idea, what's happening to you.

If I go to "http://jsbin.com/axeyok" I see an empty page. This ok so far, right?
I have no scripts enabled but Tamperscript and testem (the script I've posted 
in my earlier comment).
Google Chrome 17.0.938.0 dev, Ubuntu 11.04

The the console shows:

=== start console output ===
Tampermonkey started
run!
done!!
jQuery().jquery: 1.7
jQuery().jquery: 1.7
$().jquery: 1.7
GET http://www.google-analytics.com/ga.js 403 (Forbidden)
=== end console output ===

Now the question: who tries to set the innerHTML property? Testem does not 
contain any code that tries to and Tampermonkey shouldn't set anything cause 
there are no anchor tags that link to a "*.user.js" file.

Do you see the "$().jquery: 1.7" line?
Do you maybe have other scripts enabled?
Do you have other extensions like NotScripts or something similar that prevent 
scripts from running enabled?

Original comment by [email protected] on 15 Nov 2011 at 4:43

I allowed both versions of the plugin to run in incognito mode and disabled and 
enabled the extensions one at a time. The stable version showed the error and 
the beta version did not. However, with both extensions enabled the script 
running in beta would fail even if the script in stable was not running. Just 
having the stable plugin running would stop the beta version working, which is 
what I was probably seeing earlier.

So it's working in Beta. I've imported all my scripts to Beta and they're 
working. You can close this issue.

Original comment by [email protected] on 15 Nov 2011 at 5:07

Ok. Meanwhile I released a new stable version that contains this fix too. :)

Original comment by [email protected] on 16 Nov 2011 at 10:56

  • Changed state: Fixed
Was this page helpful?
0 / 5 - 0 ratings