0

I am trying to load jQuery using @require so I can start writing the user script. The script is failing on the first $.

Uncaught ReferenceError: $ is not defined

How do I load jQuery in a user script?

I have seen other examples on github and they make it look easy. What am I missing?

// ==UserScript==
// @name           Test
// @description    Test description
// @license        MIT License
// @charset        UTF-8
// @version        0.1
// @match          http://example.com/* 
// @require        http://code.jquery.com/jquery-1.9.1.min.js
// ==/UserScript==

$(function() {

    console.log('ok, lets start'); 

});
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
filype
  • 8,034
  • 10
  • 40
  • 66
  • Just start running commands do not do $(function() if its a userscript it gets called at a certain time. You do not have that much control of when it gets ran. – Bioto May 30 '14 at 06:04
  • [userjs] is for *Opera* but you appear to be running Chrome. Which is it? – Brock Adams May 30 '14 at 06:19
  • Chrome, isn't all `user.js` scripts meant to run on both? – filype May 30 '14 at 06:20
  • No, the cross-browser tag is [userscripts]. and `*.user.js` files are not often portable between the browsers or even between Chrome and Chrome + Tampermonkey (which is what you should use, on Chrome). – Brock Adams May 30 '14 at 06:22

1 Answers1

0

If you are using chrome to run your user scripts, you have to opt for an alternative method as @require is not supported by chrome.

Chromium does not support @require, @resource, unsafeWindow, GM_registerMenuCommand, GM_setValue, or GM_getValue.

The Chromium Project - User scripts

More details on:

Community
  • 1
  • 1
filype
  • 8,034
  • 10
  • 40
  • 66
  • 1
    This answer and [that linked page](http://www.chromium.org/developers/design-documents/user-scripts) are partially obsolete. `unsafeWindow` is now provided by Chrome (but is otherwise useless on that platform sans Tampermonkey). `GM_xmlhttpRequest` also does now support cross-domain requests. – Brock Adams May 30 '14 at 06:34