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

responseXML access error #89

Closed
bpatrik opened this issue Jun 4, 2018 · 5 comments
Closed

responseXML access error #89

bpatrik opened this issue Jun 4, 2018 · 5 comments

Comments

@bpatrik
Copy link

bpatrik commented Jun 4, 2018

Hi,

I got the following error in the latest version (1.4.8) in chrome 66.0.3359.181

Uncaught DOMException: Failed to read the 'responseXML' property from 'XMLHttpRequest':
The value is only accessible if the object's 'responseType' is '' or 'document' (was 'text').

As far as I could debug, the error seems to be in the readBody function at xhook.js:336

Might be related to #86

Any suggestions?
Thank you!
Patrik

@bpatrik bpatrik changed the title responseXML error responseXML access error Jun 4, 2018
@morsdyce
Copy link
Collaborator

morsdyce commented Jun 4, 2018

Hi,

Thanks for reporting this, is there a sample request you can share so I can test it?
I currently do not see any issues from the tests for regular requests and XML requests

@bpatrik
Copy link
Author

bpatrik commented Jun 4, 2018

Hi,

I have something like this:

const url = '...';
const request:= {
      url: 'https://raw.githubusercontent.com/bpatrik/PiGallery2/master/README.md',
      method: 'GET',
      timeout: 0,
      headers: {},
      type: 'text',
      withCredentials: false
    };

const xhr = new XMLHttpRequest();
xhr.open('GET', url + '/api/http-request?data=' + encodeURIComponent(JSON.stringify(req)), true);
if (request.type) {
     xhr.responseType = request.type;
}

xhr.send();

should I not set the type explicitly to text ?

@morsdyce
Copy link
Collaborator

morsdyce commented Jun 4, 2018 via email

morsdyce added a commit that referenced this issue Jun 11, 2018
When trying to use the XHR api set with a content type of 'text' the
browser throws an error it is unable to read responseXML as the response
isn't valid xml and the response type is not an empty string or
'document' as according to spec.

this change was implemented due to inconsistent implementation across
browsers and 3rd party network libraries which do parse xml responses
even when the response type is not set according to the spec.

In order to support all clients we now try to assign the responseXML
property when possible but fail silently when we cannot.

This will keep both behaviors consistent as incorrectly implemented
clients will be able to read the XML response while still supporting the
correctly implemented clients to not fail the request when trying to
access responseXML on an invalid request.

please see issues #86 #89 for more information.
@morsdyce
Copy link
Collaborator

Fixed in v1.4.9

Please check it out and let me know if it works for you.

Thanks

@bpatrik
Copy link
Author

bpatrik commented Jun 11, 2018

Seems to be working.
Thank you!

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

2 participants