SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.95k stars 1.24k forks source link

jQuery.sap.storage.put exeption using safari private browsing #1056

Closed hschaefer123 closed 8 years ago

hschaefer123 commented 8 years ago

OpenUI5 version: 1.38.4 (any)

Browser/version (+device/version): Safari (mac, ios)

Today i found out the hard way ;-) that safari throws an exception accessing the local storage using the private browsing mode.

Private browsing throws an QUOTA_EXCEEDED_ERR exception, when trying to set a local store property (by design).

See "Detect private browsing mode in mobile Safari on iOS5" http://m.cg/post/13095478393/detect-private-browsing-mode-in-mobile-safari-on

I think this needs to be handled/catched inside jQuery.sap.storage.put, because using the store api destory the whole UI5 app!

From my point of view, the detection should also be part of sap.ui.Device.support.localStorage to be able to easily handle this behavior inside code.

I do not know if private browsing is supported, but our B2B shop works quitre well using private browsing and with this fixes, we would have more control.

Current Workaround:

You should put an try/catch around any jQuery.sap.storage.put directive

try {
  jQuery.sap.storage.put("KEY", "VALUE");
} catch (oError) {}

or use the following snippet

this.oStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);

if (this.isLocalStorageSupported()) {
  this.oStorage.put("rememberMe", bRememberMe);
}

isLocalStorageSupported: function() {
            var sTestKey = "test", 
                oStorage = window.localStorage;
            try { 
                // Try and catch quota exceeded errors 
                oStorage.setItem(sTestKey, "1"); 
                oStorage.removeItem(sTestKey); 
                return true;
            } catch (oError) { 
                if (oError.code === DOMException.QUOTA_EXCEEDED_ERR && oStorage.length === 0) {
                    /*
                    MessageBox.information(this.getText("SafariPrivateBrowsingMsg"), {
                        title: this.getText("SafariPrivateBrowsingTitle")
                    });
                    */
                }
                return false; // throw error; 
            }
}

to be able to better control the store handling.

Regards Holger

RobertoMalatesta commented 8 years ago

Hit this myself as well. As a remedy I scrapped out localStorage and started using LokiJS with IndexedDB. [(https://github.com/techfort/LokiJS/wiki/LokiJS-persistence-and-adapters)]

As a plus side, now I have a really handy MongoDB-like NOSQL client-side database. Wrote a remote persistent layer and I'm replacing OData bureaucratic-DB almost everywhere.

Just my 2c.

--R

Michadelic commented 8 years ago

Thanks guys for the detailed analysis, and also for the code suggestions. Would you like to create a pull request? That would actually speed up the process. Anyhow, i contacted the owner and he will get back to you soon.

Internally tracked as: 1680148290

Kind Regards, Michael

hschaefer123 commented 8 years ago

Inside the Smart Widget and Personalisation service i regognized the fallback to localstorage. The SAP guys who did this catched out the same issue (pointing out with a comment).

Maybe i would be a good idea if sap internally would create tickets too ;-)

Regards Holger

sirion commented 8 years ago

I am confused - We already have a try/catch inside the put-method: https://github.com/SAP/openui5/blob/master/src/sap.ui.core/src/jquery.sap.storage.js#L132

Could you provide a code snippet or test case?

hschaefer123 commented 8 years ago

Hi Jens, i just wrote an example and testing on iPad privat browsing is fine?!?

As time of writing the issue, our login component caused the workaround?!?

So i think you can close the issue. Sorry for that. With next update of our product i will remove my workaround and see, if it will work fine.

Do not know, if i had an older version without the try/catch

Regards Holger

TobiasOetzel commented 8 years ago

Closing this for Jens,

@hschaefer123 thanks for rechecking

best regards, Tobias