We are experiencing an error on our Web site that prevents users from adding to the cart. We can see the error happening via recordings collected by Microsoft Clarity.
I believe it’s coming from this code /vendor/magento/magento2-base/lib/web/js-storage/js.storage.js:
// Remove items from a storage
function _remove() {
var storage = this._type, l = arguments.length, s = window[storage], a = arguments, a0 = a[0], to_store, tmp, i, j;
if (l < 1) {
throw new Error('Minimum 1 argument must be given');
} else if (Array.isArray(a0)) {
// If first argument is an array, remove values from storage for each item of this array
for (i in a0) {
if (a0.hasOwnProperty(i)) {
s.removeItem(a0[i]);
}
}
return true;
} else if (l == 1) {
// If only 2 arguments, remove value from storage directly
s.removeItem(a0);
return true;
} else {
// If more than 2 arguments, parse storage to retrieve final node and remove value
// Get first level
try {
to_store = tmp = JSON.parse(s.getItem(a0));
} catch (e) {
throw new ReferenceError(a0 + ' is not defined in this storage');
}
// Parse next levels and remove value
for (i = 1; i < l - 1; i++) {
tmp = tmp[a[i]];
if (tmp === undefined) {
throw new ReferenceError([].slice.call(a, 1, i).join('.') + ' is not defined in this storage');
}
}
// If last argument is an array,remove value for each item in this array
// Else remove value normally
if (Array.isArray(a[i])) {
for (j in a[i]) {
if (a[i].hasOwnProperty(j)) {
delete tmp[a[i][j]];
}
}
} else {
delete tmp[a[i]];
}
s.setItem(a0, JSON.stringify(to_store));
return true;
}
}
I am not able to recreate this error on our site.
Any suggestions on how I can track down the issue? Or what the issue might be?