| 'use strict'; |
| |
| var createBlob = require('../../deps/binary/blob'); |
| var Promise = require('../../deps/promise'); |
| var idbConstants = require('./constants'); |
| var DETECT_BLOB_SUPPORT_STORE = idbConstants.DETECT_BLOB_SUPPORT_STORE; |
| |
| // |
| // Blobs are not supported in all versions of IndexedDB, notably |
| // Chrome <37 and Android <5. In those versions, storing a blob will throw. |
| // |
| // Various other blob bugs exist in Chrome v37-42 (inclusive). |
| // Detecting them is expensive and confusing to users, and Chrome 37-42 |
| // is at very low usage worldwide, so we do a hacky userAgent check instead. |
| // |
| // content-type bug: https://code.google.com/p/chromium/issues/detail?id=408120 |
| // 404 bug: https://code.google.com/p/chromium/issues/detail?id=447916 |
| // FileReader bug: https://code.google.com/p/chromium/issues/detail?id=447836 |
| // |
| function checkBlobSupport(txn) { |
| return new Promise(function (resolve) { |
| var blob = createBlob(['']); |
| txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob, 'key'); |
| |
| txn.onabort = function (e) { |
| // If the transaction aborts now its due to not being able to |
| // write to the database, likely due to the disk being full |
| e.preventDefault(); |
| e.stopPropagation(); |
| resolve(false); |
| }; |
| |
| txn.oncomplete = function () { |
| var matchedChrome = navigator.userAgent.match(/Chrome\/(\d+)/); |
| var matchedEdge = navigator.userAgent.match(/Edge\//); |
| // MS Edge pretends to be Chrome 42: |
| // https://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx |
| resolve(matchedEdge || !matchedChrome || |
| parseInt(matchedChrome[1], 10) >= 43); |
| }; |
| }).catch(function () { |
| return false; // error, so assume unsupported |
| }); |
| } |
| |
| module.exports = checkBlobSupport; |