2

Basically, I try to send a request via the GM_xmlhttpRequest() Greasemonkey API and abort it.

Here is a demo script:

// ==UserScript==
// @name            example
// @namespace       example795cb636-1f35
// @include         https://www.google.com/
// ==/UserScript==

var ret = GM_xmlhttpRequest({
    method: "GET",
    url: "https://www.google.com/",
    onerror: function(response) {
        console.log("error : " + response.statusText);
    },
    onabort: function(response) {
        console.log("abort : " + response.statusText);
    },
    onload: function(response) {
        console.log("complete : " + response.statusText);
    }
});

try{
    ret.abort();
}
catch(e){
    console.log(ret);
    console.log(e);
}

Here is my console output: enter image description here

What am I missing?

Details:

Firefox 20.0a1
Greasemonkey 1.5

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
CronosS
  • 3,129
  • 3
  • 21
  • 28
  • If anyone is wondering, [the return value](http://wiki.greasespot.net/GM_xmlhttpRequest#Returns) is always supposed to have a method called `abort`. –  Jan 06 '13 at 18:24

1 Answers1

4

Update:
Submitted a patch that was rolled into GM version 1.9. This issue is now officially resolved.


This is a bug in Greasemonkey. In Greasemonkey's xmlhttprequester.js source, abort is not exposed properly, per Mozilla's COW interface.

The relevant code is:

var rv = {
    __exposedProps__: {
        finalUrl: "r",
        readyState: "r",
        responseHeaders: "r",
        responseText: "r",
        status: "r",
        statusText: "r"
        },
    abort: function () { return req.abort(); }
};

but should be:

var rv = {
    __exposedProps__: {
        finalUrl: "r",
        readyState: "r",
        responseHeaders: "r",
        responseText: "r",
        status: "r",
        statusText: "r",
        abort: "r"
        },
    abort: function () { return req.abort(); }
};


See related bugs:

  1. Provide abort() for GM_xmlhttpRequest
  2. GM_xmlhttpRequest response.responseText is undefined in...
  3. Use exposedProps

Patching the code fixes the bug.

You can:

  1. Fork the Greasemonkey code, and use your own version (Recommended).
    and/or
  2. File a bug report.
Brock Adams
  • 90,639
  • 22
  • 233
  • 295