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

xmlHttpRequest - finalUrl returning NULL #2692

Closed
Charles152 opened this Issue Nov 17, 2017 · 8 comments

Comments

Projects
None yet
4 participants
@Charles152

Charles152 commented Nov 17, 2017

GM.xmlHttpRequest's "finalUrl" is returning NULL on a 302 Found redirect, which is observable in Wireshark:

Wireshark Output:

Hypertext Transfer Protocol:
HTTP/1.1 302 Found\r\n
[...]
Location: (Redirect URL)

Greasemonkey output:

context : null
finalUrl : null
lengthComputable : null
loaded : null
readyState : 4
response : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
(rest of response document)
responseXML : null
status : 200
statusText : OK
total : null

This works without a problem in Tampermonkey. Tampermonkey output:

readyState : 4
responseHeaders : (list of returned headers)
finalUrl : (non-Null redirect URL)
status : 200
statusText : OK
response : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
(rest of response document)
responseXML : [object XMLDocument]
UNSENT : 0
OPENED : 1
HEADERS_RECEIVED : 2
LOADING : 3
DONE : 4

The following identical code is being used in both Greasemonkey and Tampermonkey where the URL variable is replaced for the same valid URL:

The HTTP code generating website "https://httpstat.us/302" should work as a valid test URL for this.

var URL = "https://httpstat.us/302";

GM.xmlHttpRequest({
  method: "POST",
  url: URL,
  onload: function(response) {
	try {
	  for(var i in response) {
		console.log(i + " : " + response[i]);
	  }
	}catch(e){
	  console.log(e);
	}
  }
});

At first I thought mozAnon was causing the problems (since Cookies being sent will cause a similar problem in the script), but mozAnon is another issue that seems to be happening at random and the 'finalUrl' being null is what is actually causing the problem with the script.

@Charles152 Charles152 changed the title from xmlHttpRequest - mozAnon ignored to xmlHttpRequest - finalUrl returning empty Nov 17, 2017

@Charles152 Charles152 changed the title from xmlHttpRequest - finalUrl returning empty to xmlHttpRequest - finalUrl returning NULL Nov 17, 2017

@arantius

This comment has been minimized.

Show comment
Hide comment
@arantius

arantius Nov 17, 2017

Collaborator

Yep, documentation wasn't updated perfectly; this feature is completely missing in GM4.

Collaborator

arantius commented Nov 17, 2017

Yep, documentation wasn't updated perfectly; this feature is completely missing in GM4.

@arantius arantius added this to the 4.x milestone Nov 17, 2017

@DoomTay

This comment has been minimized.

Show comment
Hide comment
@DoomTay

DoomTay Nov 18, 2017

Happens with status code of 200 or 404 as well, like https://httpstat.us/200

DoomTay commented Nov 18, 2017

Happens with status code of 200 or 404 as well, like https://httpstat.us/200

@alexgit2k

This comment has been minimized.

Show comment
Hide comment
@alexgit2k

alexgit2k Nov 21, 2017

Contributor

User-Script-Example showing the bug: bugdemo.txt

Any workarounds to get the requested url within an event-handler without finalUrl?

Contributor

alexgit2k commented Nov 21, 2017

User-Script-Example showing the bug: bugdemo.txt

Any workarounds to get the requested url within an event-handler without finalUrl?

@DoomTay

This comment has been minimized.

Show comment
Hide comment
@DoomTay

DoomTay Nov 21, 2017

Best workaround I can think of is to reuse the "URL" variable, whether it's the string provided or whatever.

DoomTay commented Nov 21, 2017

Best workaround I can think of is to reuse the "URL" variable, whether it's the string provided or whatever.

@arantius

This comment has been minimized.

Show comment
Hide comment
@arantius

arantius Nov 21, 2017

Collaborator

Pull #2720 should address this but I'd like to add a unit test before I close the issue. (Or @alexgit2k you could add it, but I don't think there's any tests of this code at all yet, so it's a tall order.)

Collaborator

arantius commented Nov 21, 2017

Pull #2720 should address this but I'd like to add a unit test before I close the issue. (Or @alexgit2k you could add it, but I don't think there's any tests of this code at all yet, so it's a tall order.)

@arantius arantius modified the milestones: 4.x, 4.1 Nov 23, 2017

@arantius

This comment has been minimized.

Show comment
Hide comment
@arantius

arantius Dec 5, 2017

Collaborator

The GM.xhr implementation, as it is, is tightly coupled to webext APIs in a way that makes it a mess to test. Pulling in this simple fix for now, tests will be added .. some time.

Collaborator

arantius commented Dec 5, 2017

The GM.xhr implementation, as it is, is tightly coupled to webext APIs in a way that makes it a mess to test. Pulling in this simple fix for now, tests will be added .. some time.

@arantius arantius closed this in d26af74 Dec 5, 2017

arantius added a commit that referenced this issue Dec 5, 2017

Merge pull request #2720 from alexgit2k/finalUrl-in-xhr-response
Add finalUrl in xhr-response, fixes #2692
@arantius

This comment has been minimized.

Show comment
Hide comment
@arantius

arantius Dec 5, 2017

Collaborator

This fix should be in 4.1beta6; testing and confirming this would be very appreciated!

https://addons.mozilla.org/firefox/downloads/file/800957/greasemonkey-4.1beta6-an+fx.xpi?src=devhub

Collaborator

arantius commented Dec 5, 2017

This fix should be in 4.1beta6; testing and confirming this would be very appreciated!

https://addons.mozilla.org/firefox/downloads/file/800957/greasemonkey-4.1beta6-an+fx.xpi?src=devhub

@alexgit2k

This comment has been minimized.

Show comment
Hide comment
@alexgit2k

alexgit2k Dec 5, 2017

Contributor

Working, thanks.

Contributor

alexgit2k commented Dec 5, 2017

Working, thanks.

badbrainz added a commit to badbrainz/greasemonkey that referenced this issue Dec 20, 2017

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