* Fix: responseType=json breaks XHR for Android 4 (Samsung default browser) and Safari prior to 7 * Remove xhr.responseType assignment without try-catch * Use _.attempt instead of try catch - PR comment
This commit is contained in:
Родитель
847404e07c
Коммит
4af2f77f24
|
@ -388,7 +388,25 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
|
|||
}
|
||||
|
||||
const acceptType = this._options.acceptType || 'json';
|
||||
this._xhr.responseType = SimpleWebRequestBase._getResponseType(acceptType);
|
||||
const responseType = SimpleWebRequestBase._getResponseType(acceptType);
|
||||
|
||||
const responseTypeError = _.attempt(() => {
|
||||
this._xhr!!!.responseType = responseType;
|
||||
});
|
||||
|
||||
if (responseTypeError) {
|
||||
// WebKit added support for the json responseType value on 09/03/2013
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=73648.
|
||||
// Versions of Safari prior to 7 and Android 4 Samsung borwsers are
|
||||
// known to throw an Error when setting the value "json" as the response type.
|
||||
//
|
||||
// The json response type can be ignored if not supported, because JSON payloads
|
||||
// are handled by mapBody anyway
|
||||
if (responseType !== 'json') {
|
||||
throw responseTypeError;
|
||||
}
|
||||
}
|
||||
|
||||
this._setRequestHeader('Accept', SimpleWebRequestBase.mapContentType(acceptType));
|
||||
|
||||
this._xhr.withCredentials = !!this._options.withCredentials;
|
||||
|
|
Загрузка…
Ссылка в новой задаче