Previously, testing for 'ms-stream' and 'moz-chunked-arraybuffer' support on the xhr object caused warnings to appear in Chrome. Since fetch will always be used instead of these when available, short-circuit and return false when fetch is available.
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
exports.fetch = isFunction(window.fetch) && isFunction(window.ReadableByteStream)
|
|
|
|
exports.blobConstructor = false
|
|
try {
|
|
new Blob([new ArrayBuffer(1)])
|
|
exports.blobConstructor = true
|
|
} catch (e) {}
|
|
|
|
var xhr = new window.XMLHttpRequest()
|
|
xhr.open('GET', '/')
|
|
|
|
function checkTypeSupport (type) {
|
|
try {
|
|
xhr.responseType = type
|
|
return xhr.responseType === type
|
|
} catch (e) {}
|
|
return false
|
|
}
|
|
|
|
// For some strange reason, Safari 7.0 reports typeof window.ArrayBuffer === 'object'.
|
|
// Safari 7.1 appears to have fixed this bug.
|
|
var haveArrayBuffer = typeof window.ArrayBuffer !== 'undefined'
|
|
var haveSlice = haveArrayBuffer && isFunction(window.ArrayBuffer.prototype.slice)
|
|
|
|
exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
|
|
// These next two tests unavoidably show warnings in Chrome. Since fetch will always
|
|
// be used if it's available, just return false for these to avoid the warnings.
|
|
exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream')
|
|
exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer &&
|
|
checkTypeSupport('moz-chunked-arraybuffer')
|
|
exports.overrideMimeType = isFunction(xhr.overrideMimeType)
|
|
exports.vbArray = isFunction(window.VBArray)
|
|
|
|
function isFunction (value) {
|
|
return typeof value === 'function'
|
|
}
|
|
|
|
xhr = null // Help gc
|