Greasemonkey @require does not work in Chrome

后端 未结 2 1222
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 11:38

I\'m trying to add jQuery using Greasemonkey\'s @require / @include method, but it doesn\'t work. The following error shows up:

Unc         


        
2条回答
  •  执笔经年
    2021-01-14 12:00

    @ic is not a valid meta-rule, so it's ignored.
    Use @require if you want to load jQuery in your user script.

    // ==UserScript==
    // @name       Foo
    // @namespace  Bar
    // @include    *
    // @require    http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
    // ==/UserScript==
    

    EDIT: In the comments, you said that you're using Chrome. Chrome does not support the @require rule. See also:

    • GreaseSpot Wiki: Cross-browser userscripting
    • Stack Overflow: Why doesn't jQuery work in Chrome user scripts (Greasemonkey)?
    • Stack Overflow: How can I use jQuery in Greasemonkey scripts in Google Chrome?

    If you want full Greasemonkey support in Chrome, use Tampermonkey.

    Clearing up confusion about User scripts in Chrome

    Chrome does not natively support GreaseMonkey. Whenever a .user.js file is loaded, it's converted to a Chrome extension in form of a Content script.

    For more information on User scripts in Chrome, see this documentation.

    The User script is literally copied into the extension's directory:

    // ==UserScript==
    // @name       Foo
    // @namespace  Bar
    // @include    *
    // @require    http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
    // ==/UserScript==
    alert(typeof $)
    

    A manifest.json file is created, based on the meta block. When the User script contains a @include rule, its matches rule will contain https://*/* and http://*/*, because of the too loose @include rule.

    The contents of the generated manifest.json looks like:

    {
       "content_scripts": [ {
          "exclude_globs": [  ],
          "include_globs": [ "*" ],
          "js": [ "script.js" ],
          "matches": [ "http://*/*", "https://*/*" ],
          "run_at": "document_idle"
       } ],
       "converted_from_user_script": true,
       "description": "",
       "key": "+.... some key ...=",
       "name": "Foo",
       "version": "1.0"
    }
    

提交回复
热议问题