closure-library
closure-library copied to clipboard
XhrIo withCredentials on Firefox using synchronous XMLHtppRequest.open will always throw an error due to Xhrio.js setting withCredentials to false no matter what
XhrIo withCredentials on Firefox using synchronous XMLHtppRequest.open will always throw an error due to Xhrio.js setting withCredentials to false no matter what
Explanation of the thrown error can be found here: https://bugzilla.mozilla.org/show_bug.cgi?id=736340
Xhrio.js contains this bit of problematic code in the method
goog.net.XhrIo.prototype.send = function() ...:
[...]
if (goog.object.containsKey(this.xhr_, 'withCredentials')) {
this.xhr_.withCredentials = this.withCredentials_;
}
[...]
A quick solution could be to test if this.widthCredentials_ is something else then false.
How to reproduce:
goog.provide('fusionmd.SyncXmlHttpFactory');
goog.require('goog.net.DefaultXmlHttpFactory');
/**
* An XML HTTP factory that creates synchronous XHRs regardless of which option
* (sync/async) is actually used. The factory overcomes the Closure Library
* limitation that only asynchronous XHRs are created.
*
* var syncXhr = new goog.net.XhrIo(new fusionmd.SyncXmlHttpFactory());
*
* @constructor
* @extends {goog.net.DefaultXmlHttpFactory}
*/
fusionmd.SyncXmlHttpFactory = function() {
goog.base(this);
};
goog.inherits(fusionmd.SyncXmlHttpFactory, goog.net.DefaultXmlHttpFactory);
/**
* Always opens a synchronous XHR.
*
* @this {!XMLHttpRequest}
* @param {string} method
* @param {string} url
* @private
*/
fusionmd.SyncXmlHttpFactory.syncXhrOpen_ = function(method, url) {
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#open()
/*async
An optional boolean parameter, defaulting to true, indicating whether or not to perform the operation asynchronously. If this value is false, the send()method does not return until the response is received. If true, notification of a completed transaction is provided using event listeners. This must be true if the multipart attribute is true, or an exception will be thrown.
Note: Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), synchronous requests on the main thread have been deprecated due to the negative effects to the user experience.*/
XMLHttpRequest.prototype.open.call(this, method, url, false);
};
/** @override */
fusionmd.SyncXmlHttpFactory.prototype.createInstance = function() {
var instance;
instance = goog.base(this, 'createInstance');
instance.open = fusionmd.SyncXmlHttpFactory.syncXhrOpen_;
return instance;
};
Then:
// ping the online handler service synchronously to set connection status
var syncXhr = new goog.net.XhrIo(new fusionmd.SyncXmlHttpFactory());
syncXhr.send("/yourRestCall");
this.isOnline_ = syncXhr.isSuccess();
Thanks for reporting this. Do you think you could put together a pull request to implement your workaround?
Well I tried, the CLANG thingy seems to break on my comment, it does not specify anything to do.
The line I think you're referring to has a trailing whitespace. Running clang on your file will solve it: https://github.com/google/closure-library/wiki/Formatting-.js-with-clang-format
On Fri, May 6, 2016 at 12:19 PM, gmalartre [email protected] wrote:
Well I tried, the CLANG thingy seems to break on my comment, it does not specify anything to do.
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/google/closure-library/issues/702#issuecomment-217535243