问题描述
我最近尝试更新我以前的 webapp 项目之一,我需要从服务器下载文件并将它们存储在设备上(以便稍后访问)。 为了实现这一点,我使用了 navigator.persistentStorage(或 navigator.webkitPersistentStorage)及其 requestQuota 函数,如 https://developer.mozilla.org/en-US/docs/Web/API/LocalFileSystem#using_persistent_storage
所示问题是,当我在本地测试我的应用程序(通过 file:/// 访问 index.html)时,requestQuota 会触发“您是否要允许”chrome 弹出窗口,但是当我选择“是”时,我得到一个以下 DOMError 失败:
{
message: "The implementation did not support the requested type of object or operation."
name: "NotSupportedError"
}
另一方面,当我访问部署在其远程服务器上的应用程序时,一切都像魅力一样。
意识到本地文件 API 的限制 (https://developer.mozilla.org/en-US/docs/Web/API/File_and_Directory_Entries_API/Introduction#file),我使用自定义 chrome 运行了这些测试: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --ssl-version-min=tls1 --allow-file-access-from-files --allow-file-access --disable -web-security --user-data-dir="C:\tmp\chromeDev"
为了在我的应用程序环境之外进行测试,我尝试了 chrome inspect 中的简单行:
navigator.webkitPersistentStorage.requestQuota(1024*1024,r => console.log('success'),e => console.log('failure : ' + e)
);
在 chrome 中打开的随机本地 index.html(使用 file:///)-->“失败”。 在随机网站上(使用 https://)-->“成功”。
我降级了我的 Chrome 并发现所有这些问题只发生在 Chrome 86 之后。
理想情况下,我应该升级我的应用程序以使用 IndexedDb API,但在短期内,非常欢迎修复或解决方法:)
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)