window.addEventListener('load', () => {
    ['openUserModal', 'openItemModal', 'openWarehouseModal', 'openContactStatement'].forEach(fnName => {
        const originalFn = window[fnName];
        if (originalFn) {
            window[fnName] = function(...args) {
                try {
                    originalFn.apply(this, args);
                } catch(e) {
                    alert('Error in ' + fnName + ': ' + e.message + '\n' + e.stack);
                    console.error(e);
                }
            };
        }
    });
});
