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

GM.xmlHttpRequest not reaching readyState==4 #2980

Closed
pjb1008 opened this Issue Jul 2, 2018 · 12 comments

Comments

Projects
None yet
4 participants
@pjb1008
Copy link

pjb1008 commented Jul 2, 2018

Hi,

I am using GM.xmlHttpRequest to send and receive XML documents. (They're actually just strings as far as GM is concerned - I serialise and parse them myself.)

This worked in GM 4.4, but with GM 4.5 the onload function is never called so my program stops at that point. onreadystatechange is called with readyState 3, but the readyState never gets to 4.

I can't see anything in the changelog that looks like a relevant change. Any help would be appreciated.

Peter

@arantius

This comment has been minimized.

Copy link
Collaborator

arantius commented Jul 2, 2018

https://wiki.greasespot.net/Greasemonkey_Manual:Getting_Help#What_to_Say

Exact version of everything involved? Exact script that produces this?

@arantius

This comment has been minimized.

Copy link
Collaborator

arantius commented Jul 2, 2018

https://github.com/greasemonkey/greasemonkey/blob/master/test/scripts/api-xhr.user.js

We didn't have one (!) so I just added a test script, which for me logs:

gm_xhr onprogress lengthComputable:  true GM.xmlhttpRequest() test.:507:5
gm_xhr onprogress loaded:  1081 GM.xmlhttpRequest() test.:508:5
gm_xhr onprogress total:  1081 GM.xmlhttpRequest() test.:509:5
gm_xhr onprogress lengthComputable:  true GM.xmlhttpRequest() test.:507:5
gm_xhr onprogress loaded:  1081 GM.xmlhttpRequest() test.:508:5
gm_xhr onprogress total:  1081 GM.xmlhttpRequest() test.:509:5
GM_xmlhttpRequest works:  <!DOCTYPE HTML PUBLIC "-//W3C/ GM.xmlhttpRequest() test.:504:5 

I.e. it works.

@pjb1008

This comment has been minimized.

Copy link
Author

pjb1008 commented Jul 2, 2018

@pjb1008

This comment has been minimized.

Copy link
Author

pjb1008 commented Jul 2, 2018

@arantius arantius added this to the 4.6 milestone Jul 2, 2018

@makyen

This comment has been minimized.

Copy link

makyen commented Jul 3, 2018

@pjb1008 You have not provided the information mentioned in the What to Say link. Specifically, Operating System and Firefox version.

I mention this because I'm tracking down an issue in a script I support that is also related to GM.xmlHttpRequest(), but which I haven't been able to duplicate in all environments. Thus, to know if the problem is the same as this one, it would be helpful to have those details from you.

@pjb1008

This comment has been minimized.

Copy link
Author

pjb1008 commented Jul 3, 2018

@pjb1008

This comment has been minimized.

Copy link
Author

pjb1008 commented Jul 4, 2018

@Cerberus-tm

This comment has been minimized.

Copy link

Cerberus-tm commented Jul 4, 2018

@pjb1008 Hmm if you could add in a real url, then people could test it more easily. Would it be possible to replace the censored url with some other, real url that testers can access?

@arantius

This comment has been minimized.

Copy link
Collaborator

arantius commented Jul 4, 2018

This script directly reproduces the failure; onprogress fires but onload does not, when response is XML.

@arantius arantius added the confirmed label Jul 4, 2018

@arantius

This comment has been minimized.

Copy link
Collaborator

arantius commented Jul 9, 2018

Finally found a traceback of the error:

 DataCloneError: The object could not be cloned. on-user-script-xhr.js:80
_sendMessage     resource://gre/modules/ExtensionChild.jsm:279:18
postMessage     resource://gre/modules/ExtensionChild.jsm:223:5
postMessage     resource://gre/modules/ExtensionChild.jsm:179:9
xhrEventHandler     moz-extension://.../src/bg/on-user-script-xhr.js:80:5
xhrEventHandler self-hosted:1031:17 

The true failure seems to be in passing the message. I "fixed" a bug that copied the responseXML to nowhere in an unrelated clean up CL. Now it's being passed, to a place that it can't be handled. The XML object is not message-passing-cloneable. And we're doing the XHR in the background process, so we have to message pass the results to the content process where the user script is running.

@arantius arantius closed this in 80b179b Jul 9, 2018

@arantius

This comment has been minimized.

Copy link
Collaborator

arantius commented Jul 9, 2018

This should be fixed in the latest nightly build ( https://arantius.com/misc/gm-nightly/greasemonkey-2018.07.09.nightly.33eca3f6.xpi ). Confirmation would be great!

@Cerberus-tm

This comment has been minimized.

Copy link

Cerberus-tm commented Jul 9, 2018

That seems to work for me, thanks for the fix!:
y9aq08h 1
[Virtual Machine, Windows 7, Firefox 61.0.1 (32 bits), the GM nightly from the previous message.]

The only thing that doesn't seem to work is getting an html file and having it parsed like a DOM, which did work in GM 3. The following code (except for GM.xmlHttpRequest, of course) worked in GM 3, but not in GM 4:

// ==UserScript==
// @name        GM.xmlhttpRequest() test w/ XML.
// @description Exercise the XHR API, downloading an XML file.
// @version     1
// @grant       GM.xmlHttpRequest
// ==/UserScript==

GM.xmlHttpRequest({
  method: 'GET',
  //url: 'http://google.com/sitemap.xml',
  url: 'http://google.com/',  //This has been added.
  responseType: "document",  //This has been added.
  onload: function(response) {
    //console.log('GM_xmlhttpRequest works: ', response.responseText.substring(0, 30));
    console.log( response.responseXML);  //This has been added.
  },
  onprogress: function(e) {
    console.log('gm_xhr onprogress lengthComputable: ', e.lengthComputable);
    console.log('gm_xhr onprogress loaded: ', e.loaded);
    console.log('gm_xhr onprogress total: ', e.total);
  }
});

It gives the following error in the browser console (though nothing in the web console):

 DataCloneError: The object could not be cloned. on-user-script-xhr.js:81
_sendMessage
resource://gre/modules/ExtensionChild.jsm:279:18
postMessage
resource://gre/modules/ExtensionChild.jsm:223:5
postMessage
resource://gre/modules/ExtensionChild.jsm:179:9
xhrEventHandler
moz-extension://579a1921-87ee-4388-8d08-55e0837f90e1/src/bg/on-user-script-xhr.js:81:5
xhrEventHandler self-hosted:1027:17 

Screenshot:

kzvvkrn 1

Or is that entirely unrelated? Should I file it as a separate issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.