demo · v138

Quota pressure lab

Write data to localStorage in chunks until a QuotaExceededError fires, then inspect the error object. Chrome 138 makes it a proper DOMException — so instanceof DOMException now works. Compare all three catching patterns side by side.

Estimated localStorage used: — / 5 MB
64 KB
0 KB written

QuotaExceededError caught

error.name— error.message— error.code— instanceof DOMException— instanceof Error— error.quota— error.requested—

Catching patterns

Pattern Code Works pre-138 Works 138+ Result
instanceof DOMException e instanceof DOMException no yes —
name check e.name === 'QuotaExceededError' yes yes —
instanceof QuotaExceededError e instanceof QuotaExceededError no yes (138+) —
legacy code check e.code === 22 yes yes —

the code

try {
  localStorage.setItem('data', hugeString);
} catch (e) {
  // Chrome 138+: e is now a real DOMException
  if (e instanceof DOMException) {
    console.log(e.name);       // "QuotaExceededError"
    console.log(e.code);       // 22
    console.log(e.quota);      // total quota bytes (where supported)
    console.log(e.requested);  // bytes that were requested (where supported)
  }

  // Backward-compatible check (works in all browsers):
  if (e.name === 'QuotaExceededError' || e.code === 22) {
    showStorageFullUI();
  }
}

see also