gpt4 book ai didi

javascript - Google 登录无法在 Safari 私有(private)模式下工作

转载 作者:搜寻专家 更新时间:2023-11-01 04:40:42 26 4
gpt4 key购买 nike

我已经使用 this docs 在我的网络应用程序中包含了 Google 登录但是当我尝试以私有(private)模式从 Safari 加载网站时,我总是在控制台中收到以下错误

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

我知道私有(private)模式下的 safari 不允许在 localStorage 中写入,但是否有任何解决方法可以让 google 登录在私有(private)模式下也能正常工作?

谢谢

最佳答案

不要让 localStorage/sessionStorage setItem 在 Safari 隐私浏览模式下抛出错误

看看这个: 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 无痕浏览会导致此类问题。解决此问题的最简单方法是更改​​函数 localStorage。

试试这个

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;
}
}

您可以在此处找到详细的文档和其他解决方案:https://github.com/marcuswestin/store.js/issues/42

关于javascript - Google 登录无法在 Safari 私有(private)模式下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33200681/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com