Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Greasemonkey 4.0) error 'GM' is not defined [ESLint] #122

Closed
darkred opened this issue Nov 13, 2017 · 2 comments
Closed

(Greasemonkey 4.0) error 'GM' is not defined [ESLint] #122

darkred opened this issue Nov 13, 2017 · 2 comments

Comments

@darkred
Copy link

darkred commented Nov 13, 2017

Continuation from eslint/eslint#9621 (comment) :


Tell us about your environment

  • ESLint Version: 4.11.0
  • Node Version: 9.1.0 x64
  • npm Version: 5.5.1

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
module.exports = {
    "env": {
        "browser": true,
		"greasemonkey": true,
    },
	"extends": "eslint:recommended",
    "parserOptions": {      // see https://eslint.org/docs/user-guide/configuring
        "ecmaVersion": 8,
        "sourceType": "script",
        "ecmaFeatures": {
            "impliedStrict": true,
        }
    },
    "rules": {
        "semi": ["warn","always"],
    }
};


What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

// ==UserScript==
// @name     GM set/get demo
// @grant    GM.getValue
// @grant    GM.setValue
// ==/UserScript==

(async function() {
	let i = await GM.getValue('i', 0);
	GM.setValue('i', i + 1);
})();
eslint 1.js

What did you expect to happen?

No errors should be found.

What actually happened? Please include the actual, raw output from ESLint.

It found the following 2 errors:

C:\Users\Kostas\Desktop\1.js
  8:16  error  'GM' is not defined  no-undef
  9:2   error  'GM' is not defined  no-undef

✖ 2 problems (2 errors, 0 warnings)

That's because, since Greasemonkey 4.0 :

There is only one object provided to user scripts now, named GM.
It has several properties. One of them is info – the equivalent of the old GM_info.
There are also several methods of this object:

  • getResourceUrl,
  • deleteValue,
  • getValue,
  • listValues,
  • setValue,
  • xmlHttpRequest.

To use these methods you still need @grant, and use the new name, e.g.:

 // @grant GM.setValue

The new form has a dot, where the old form has an underscore.
You may specify both @grants, if you'd like to be compatible with Greasemonkey 4 and other user script engines at the same time.
As of today, there is no support for:

  • GM_log (use console.log),
  • GM_addStyle,
  • GM_registerMenuCommand, nor
  • GM_getResourceText.

The complete list of the GM obect's properties is the following: (Greasemonkey_Manual:API)

  • GM.info
  • GM.deleteValue
  • GM.getValue
  • GM.listValues
  • GM.setValue
  • GM.getResourceUrl
  • GM.openInTab
  • GM.setClipboard
  • GM.xmlHttpRequest, and
  • unsafeWindow

In other words, the 'Greasemonkey' environment should be updated to include the GM object and its properties. (all the old GM_* grants should also be maintained, even the 4 currently not supported ones, for use by other script engines) .


I also quote the reply by @platinumazure :

Our environment globals come from the globals repository. I think it would probably make more sense to file an issue there.

Looking at their main global data file, I see that the old properties are the only ones present

@sindresorhus
Copy link
Owner

Pull request welcome :)

@darkred
Copy link
Author

darkred commented Nov 15, 2017

@sindresorhus I hope it's ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants