| 35 | }; |
| 36 | |
| 37 | function isQuotaError(storage: Storage, e: unknown) { |
| 38 | return ( |
| 39 | e instanceof DOMException && |
| 40 | // everything except Firefox |
| 41 | (e.code === 22 || |
| 42 | // Firefox |
| 43 | e.code === 1014 || |
| 44 | // test name field too, because code might not be present |
| 45 | // everything except Firefox |
| 46 | e.name === 'QuotaExceededError' || |
| 47 | // Firefox |
| 48 | e.name === 'NS_ERROR_DOM_QUOTA_REACHED') && |
| 49 | // acknowledge QuotaExceededError only if there's something already stored |
| 50 | storage.length !== 0 |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | export class StorageAPI { |
| 55 | storage: Storage | null; |