localStorage和'file:'协议不是持久的,SQLite给出了SECURITY_ERR

问题描述 投票:3回答:2

Introduction

我使用RapidWeaver - Mac OS X CMS应用程序 - 它不使用服务器环境。它有一个编辑器和一个预览模式。预览模式是基于Webkit的渲染器,我可以像在Safari中一样使用“Inspect Element”。

我想使用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.

这基本上包含了我的问题,我将真诚地感谢任何答案或评论。

javascript sqlite webkit local local-storage
2个回答
2
投票

使用以下解决方案:Implementing a WebView database quota 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 app store。


1
投票

localStorage是一种html5机制,可以为脚本提供比cookie更多的空间。 Safari支持它:https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html

我不知道它对于基于file:///的应用程序应该具有什么(如果有的话)路径限制。

编辑:进一步研究路径限制,我看到你得到的应该与Safari一起工作,FF最近修复了一个错误,使其无法在那里工作:https://bugzilla.mozilla.org/show%5Fbug.cgi?id=507361

© www.soinside.com 2019 - 2024. All rights reserved.