Solving the ‘QUOTA_EXCEEDED_ERR’ message when using local storage on Motorola RhoElements browsers

Working with JavaScript exceptions can be quirky as descriptions of these exceptions sometimes does not make any sense. In this particular case I was working on a Motorola device lately which was running the RhoElements 4.x web browser. The Motorola RhoElements browser is part of the RhoMobile Suite of Motorola, which allows web developers to have a closer hardware integration with Motorola devices.

A strange bug popped up however while I was trying to use local storage to store offline data. The QUOTA_EXCEEDED_ERR exception pops up when I try to store local data. This error is known tot pop up when you use Mobile Safari in Private Browsing Mode but I’m not using Mobile Safari obviously. This is the code snippet I used to set data into local storage:

set: function (name, value) {
    try {
        localStorage.setItem(name, value);
    } catch (e) {
        if (e == QUOTA_EXCEEDED_ERR) {
            alert('Quota exceeded!');
        }
    }
}

Browsing the Motorola forums finally led to a discussion mentioning both this erratic behavior as well as the solution. I was in fact using a dash (‘-‘) in my host name which leads to this strange behavior. It has been promised by a Motorola service desk employee to be solved in 4.2. Currently I’m working on 4.0 so unfortunately I can’t check this. Nevertheless, I’m using the IP address instead of the FQHN for now to bypass this issue.