* Detect if storage is full or approaching capacity. * Returns true if storage is at or near capacity.
()
| 628 | * Returns true if storage is at or near capacity. |
| 629 | */ |
| 630 | private async detectStorageFull() { |
| 631 | try { |
| 632 | const estimate = await navigator.storage.estimate(); |
| 633 | const {quota, usage} = estimate; |
| 634 | |
| 635 | // Handle cases where quota or usage might be undefined |
| 636 | if (typeof quota !== 'number' || typeof usage !== 'number') { |
| 637 | return; |
| 638 | } |
| 639 | |
| 640 | // Consider storage "full" if usage is >= 95% of quota |
| 641 | // This provides a safety buffer before actual storage exhaustion |
| 642 | const usagePercentage = (usage / quota) * 100; |
| 643 | const isStorageFull = usagePercentage >= 95; |
| 644 | |
| 645 | if (isStorageFull) { |
| 646 | this.debugHandler.log( |
| 647 | 'Storage is full or nearly full', |
| 648 | `DataGroup(${this.config.name}@${this.config.version}).detectStorageFull()`, |
| 649 | ); |
| 650 | } |
| 651 | } catch { |
| 652 | // Error estimating storage, possibly by unsupported browser. |
| 653 | } |
| 654 | } |
| 655 | } |
no test coverage detected