문제

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

도움이 되었습니까?

해결책

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.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top