Google login doesn't work in private safari mode

I have included Google in my webapp using these documents , but when I try to download a site from Safari in private mode, I always get the following error in the console

QuotaExceededError: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota. setItem4187590794-idpiframe.js:19:293 g4187590794-idpiframe.js:19:293 Ea4187590794-idpiframe.js:30 (funzione anonima)4187590794-idpiframe.js:33 onreadystatechange4187590794-idpiframe.js:11:477 

I know that safari in private mode does not allow writing to localStorage , but is there any workaround that allows google signin to work also in private mode?

thanks

+5
source share
1 answer

Do not allow localStorage / sessionStorage setItem to throw errors in Safari private browsing mode.

Take a look at this: https://gist.github.com/philfreo/68ea3cd980d72383c951

 // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem // throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem // to avoid the entire page breaking, without having to do a check at each usage of Storage. if (typeof localStorage === 'object') { try { localStorage.setItem('localStorage', 1); localStorage.removeItem('localStorage'); } catch (e) { Storage.prototype._setItem = Storage.prototype.setItem; Storage.prototype.setItem = function() {}; alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.'); } } 

Safari Private Browsing is known to cause such problems. The easiest way to fix this is to change the localStorage function.

try it

 function isLocalStorageNameSupported() { var testKey = 'theTestKey', storage = window.sessionStorage; try { storage.setItem(testKey, '1'); storage.removeItem(testKey); return localStorageName in win && win[localStorageName]; } catch (error) { return false; } } 

Here you can find detailed documentation and other solutions: https://github.com/marcuswestin/store.js/issues/42

0
source

Source: https://habr.com/ru/post/1233974/


All Articles