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

Using the (default) scratchpad editor leaves confusing "run" menu items #1771

Closed
cathalgarvey opened this issue Jul 21, 2013 · 11 comments
Closed
Milestone

Comments

@cathalgarvey
Copy link

Hello,
Recently started using Greasemonkey, and am really enjoying it already. So far, almost everything works fine for me; metadata is correctly parsed to get @includes, @name, @description, etc.

I have yet to use or try @require, but I have discovered that @grant appears not to work. Below is some example code. Removing all @grant statements doesn't make auto-inference work, so I have been so far unable to use any GM_ functions.

I'm using Greasemonkey 1.10 on IceWeasel, a rebranded form of Firefox, version 20:
http://www.geticeweasel.org/

Compatibility should not be an issue; the changes made to IceWeasel are minimal and all other extensions and features of Greasemonkey work well..

Scratchpad:

// ==UserScript==
// @name testgrants
// @namespace http://foo.bar.tld/asdfghjkl
// @description Testing whether or why "@grant" statements are not working in GM1.10 in IceWeasel 20.
// @include http://*
// @include https://*
// @Version 1
// @grant GM_log
// @grant GM_xmlhttpRequest
// ==/UserScript==
//;

// First error message below is with this log statement uncommented;
// recommented to demonstrate bug with GM_xmlhttpRequest
//GM_log("Making xhr request to get final location of 'bit.ly/qwerty'");

GM_xmlhttpRequest({
url: "http://bit.ly/qwerty",
method: "HEAD",
synchronous: true,
onload: function(response) {
var final;

return final = response.finalUrl;

}
});

GM_log("Final url: " + final);
/*
Exception: GM_log is not defined
@Scratchpad/3:14
/
/

Exception: GM_xmlhttpRequest is not defined
@Scratchpad/3:16
*/

@cathalgarvey
Copy link
Author

Update: Have installed Firefox 22 to test whether it's IceWeasel-specific, and it appears not to be.

@hurda
Copy link

hurda commented Jul 21, 2013

Your script gives me this error:

Sun Jul 21 2013 16:35:56
Error: final is not defined
Source file: file:///C:/Users/user/AppData/Roaming/Mozilla/Firefox/Profiles/abs4ddqs.default/gm_scripts/fa/fa.user.js
Line: 29

This works for me:

GM_xmlhttpRequest({
  url: "http://bit.ly/qwerty",
  method: "HEAD",
  synchronous: true,
  onload: function(response) {
    try { 
      GM_log("Final url: " + response.finalUrl);
    } catch(ex) {
      GM_log('http data from ' + url + ' could not be parsed: ' + ex);
    }
  }
});

@cathalgarvey
Copy link
Author

Sorry, must have misnamed var. Never saw the error my end as the GM functions never run anyway.

hurda notifications@github.com wrote:

Your script gives me this error:

Sun Jul 21 2013 16:35:56
Error: final is not defined
Source file:
file:///C:/Users/user/AppData/Roaming/Mozilla/Firefox/Profiles/abs4ddqs.default/gm_scripts/fa/fa.user.js
Line: 29

This works for me:

GM_xmlhttpRequest({
 url: "http://bit.ly/qwerty",
 method: "HEAD",
 synchronous: true,
 onload: function(response) {
   try { 
     GM_log("Final url: " + response.finalUrl);
   } catch(ex) {
     GM_log('http data from ' + url + ' could not be parsed: ' + ex);
   }
 }
});

Reply to this email directly or view it on GitHub:
#1771 (comment)

Sent from my Android device with K-9 Mail. Please excuse my brevity.

@hurda
Copy link

hurda commented Jul 21, 2013

Oh, I just saw the Scratchpad-Errors.
As far as I know you can't use GM_* in Scratchpad.

@arantius
Copy link
Collaborator

Do not pick "run" in scratchpad unless your script is @grant none and has no side effects. Which basically means: do not pick "run" in scratchpad. Like any other editor, just save and reload the page.

I worried a bit about this early on. I suppose we'll have to hide those menu options when you're editing a user script to avoid confusion.

@cathalgarvey
Copy link
Author

Quite right about the scratchpad issue, sorry. In my innocence I thought GM was launching scratchpad with some background hack to enable testing with "run".

However, despite now having GM_log and GM_xmlhttpRequest appear successfully in my code, GM_log still does not work (GM-xhr works fine!).

Here's the code I've written for Bandcamp: You can see at the outset that I detect GM_log and test it, but proceed with using console.log. To date I have never seen GM_log output, which was part of my original confusion in this issue: I'd been using GM_log to test whether GM_xmlhttpRequest was being detected, and its output!

To clarify prior to FAQs: I have modified the appropriate about:config settings as directed in the wiki to make GM_log function correctly, and while I do have firebug installed I have also been looking in the "normal" log.

Should I open a new issue with this, considering that I've narrowed down my problem considerably? For the record, this issue is affecting me with FF22 as well as Iceweasel 20. GM 1.1 in both cases, I think.

@cathalgarvey
Copy link
Author

Derp, never linked to referred-to code:
https://userscripts.org/scripts/review/173950

@hurda
Copy link

hurda commented Jul 23, 2013

I've taken this part of the script, and it's working fine with and without the @grant:

log = console.log;

log("Beginning ffbandcamp script.");

if (typeof GM_log !== "undefined" && GM_log !== null) {
  log("Found GM_log.");
  GM_log("This is from GM_log.");
} else {
  console.log("GM_log not found!");
}

Log-messages: http://i.imgur.com/aPYgRAZ.png

Whatever the cause of your problem is, it's not in GM or the script.

@arantius
Copy link
Collaborator

It's worth leaving this issue open to track what happens when selecting the "run" scratchpad commands. I've thought about improving that in the past, and this confirms that it's valuable. Creating a separate issue to track whether/how GM_log is broken is valuable.

@cathalgarvey
Copy link
Author

OK, new issue opened. Thanks for help here!
#1773

@GoGunner
Copy link

GoGunner commented Nov 1, 2013

In removing the menu items that are nonsensical to a new user, the thing that the scratch pad is useful for is gone. If you use an external editor with out a syntax checker the scratch pad inspect is the first thing to use to show you your missing parameters or miss typed or incorrectly capitalized words.I just updated grease and now have to go back to the previous version.

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

No branches or pull requests

4 participants