gpt4 book ai didi

javascript - localStorage 和 'file:' 协议(protocol)不持久,SQLite 给出 SECURITY_ERR

转载 作者:行者123 更新时间:2023-11-29 10:52:32 25 4
gpt4 key购买 nike

简介

我使用 RapidWeaver——Mac OS X CMS 应用程序——它不使用服务器环境。它有一个编辑器和一个预览模式。预览模式是基于 Webkit 的渲染器,我可以使用“检查元素”,就像您通常在 Safari 中所做的那样。

我想使用 localStorage 或 SQLite 存储工具栏的一些设置。我已经阅读了一些有关 indexedDB 的信息,但我没有找到关于如何使用它的具体实现。

localStorage 的问题

当我处于预览模式时,localStorage 工作正常,当我在编辑器和预览模式之间切换时,url — location.href — 略有改变:

file:///private/var/folders/s7/x8y2s0sd27z6kdt2jjdw7c_c0000gn/T/TemporaryItems/RapidWeaver/98970/document-143873968-28/RWDocumentPagePreview/code/styled/index.html

file:///private/var/folders/s7/x8y2s0sd27z6kdt2jjdw7c_c0000gn/T/TemporaryItems/RapidWeaver/98970/document-143873968-29/RWDocumentPagePreview/code/styled/index.html

document-143873968-28 变为文档-143873968-29

我读到的关于 localStorage 的内容,它基本上是用于 FireFox 的 globalStorage[location.hostname]。据我所知,Safari 不支持 globalStorage,因此我无法尝试。

SQLite 的问题

当我尝试打开数据库时:

var shortName = 'mydatabase';
var version = '1.0';
var displayName = 'My Important Database';
var maxSize = 65536; // in bytes
var db = openDatabase(shortName, version, displayName, maxSize);

我在我的控制台中得到了这个:

SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

我的问题基本上就结束了,我将不胜感激任何真诚的回答或评论。

最佳答案

使用以下解决方案:Implementing a WebView database quota delegate通过一些修改,我能够让它工作。

以下委托(delegate)方法对我有用(放置在您的 webViewDelegate 中):

- (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(id) origin database:(NSString *)databaseIdentifier
{
static const unsigned long long defaultQuota = 5 * 1024 * 1024;
if ([origin respondsToSelector: @selector(setQuota:)]) {
[origin performSelector:@selector(setQuota:) withObject:[NSNumber numberWithLongLong: defaultQuota]];
} else {
NSLog(@"could not increase quota for %@", defaultQuota);
}
}

默认情况下,数据库被赋予 0 字节,这会导致您在上面看到模糊的错误消息。在没有足够空间时尝试创建数据库后调用上述方法。请注意,此方法是在 WebUIDelegatePrivate.h ( http://opensource.apple.com/source/WebKit/WebKit-7533.16/mac/WebView/WebUIDelegatePrivate.h ) 中定义的,使用它可能会阻止您将应用程序提交到 Mac 应用程序商店。

关于javascript - localStorage 和 'file:' 协议(protocol)不持久,SQLite 给出 SECURITY_ERR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7540904/

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