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

Setting XHR response type fails due to xhr.responseType being modified before XHR is opened #65

Open
robertknight opened this issue Sep 6, 2014 · 1 comment

Comments

@robertknight
Copy link

http-browserify accepts a 'responseType' parameter to set the XHR response type. However, in Firefox 31 at least, the logic to set the response type always fails because it is set before xhr.open() is called.

The call to set 'xhr.responseType = params.responseType' fails with 'An attempt was made to use an object that is not, or is no longer, usable' ala. http://stackoverflow.com/questions/13216903/get-binary-data-with-xmlhttprequest-in-a-firefox-extension

@robertknight
Copy link
Author

According to the XHR spec (http://xhr.spec.whatwg.org/#the-responsetype-attribute) and https://bugzilla.mozilla.org/show_bug.cgi?id=707484 it is legal to set the responseType attribute before opening the request. However, this doesn't work with current versions of Firefox.

robertknight added a commit to robertknight/http-browserify that referenced this issue Sep 6, 2014
According to the XHR spec (http://xhr.spec.whatwg.org/#the-responsetype-attribute) and
https://bugzilla.mozilla.org/show_bug.cgi?id=707484 it is legal to set the responseType attribute
before opening the request. However, this doesn't work with current versions of Firefox and results
in an exception.

Work around this issue by setting the xhr.responseType attribute only
after opening the request.

Also if the caller explicitly specifies a desired response type, report
an error instead of silently returning an unexpected data type if the
xhr.responseType assignment fails.

Fixes browserify#65
robertknight added a commit to robertknight/passcards that referenced this issue Sep 6, 2014
Set the response type for XHR requests to 'arraybuffer' to ensure
correct delivery of binary data when making HTTP requests in
the browser.

This required working around an issue with XMLHttpRequest.responseType
described in browserify/http-browserify#65
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

Successfully merging a pull request may close this issue.

1 participant