localStorage 和“文件:”协议不持久,SQLite 给出 SECURITY_ERR

发布于 2024-12-06 10:59:45 字数 1377 浏览 0 评论 0原文

简介

我使用 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 变为 document-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.

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

Introduction

I work with RapidWeaver — Mac OS X CMS application — and it uses no server environment. It has an editor and a preview mode. The preview mode is a Webkit based renderer, and I can use 'Inspect Element', like you normally could do in Safari.

I want to store some settings for a toolbar, either using localStorage or SQLite. I have read some information about indexedDB, though I have found no concrete implementations on how to use it.

Problems with localStorage

localStorage works fine when I stay in the preview mode, when I switch between editor and preview mode the url — location.href — is slightly altered:

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 changes into
document-143873968-29

What I have read about localStorage, that it's basically globalStorage[location.hostname] for FireFox. As far as I know globalStorage is not supported in Safari, so I can't try that.

Problems with SQLite

When I try to open a database:

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

I get this in my console:

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

That basically wraps up my question, I will appreciate any answers or comments sincerely.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

碍人泪离人颜 2024-12-13 10:59:45

使用以下解决方案:通过一些修改实现 WebView 数据库配额委托 我能够让它发挥作用。

以下委托方法对我有用(放置在您的 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 应用程序商店。

Using the following solution: Implementing a WebView database quota delegate with a few modifications I was able to get it to work.

The following delegate method worked for me (place in your 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); 
  }
}

By default the database is given 0 bytes, which results in the vague error message you get above. The above method is called after an attempt is made to create a database when there is not enough space. Note that this method is defined in WebUIDelegatePrivate.h ( http://opensource.apple.com/source/WebKit/WebKit-7533.16/mac/WebView/WebUIDelegatePrivate.h ) and using may preclude you from submitting your app to the mac app store.

朦胧时间 2024-12-13 10:59:45

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

localStorage is a html5 mechanism to give scripts a bit more space than cookies. Safari supports it: https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html

I don't know offhand what, if any, path restrictions it should have for file:/// based apps.

Edit: looking into the path restrictions further, I see that what you got should work with Safari, FF recently fixed a bug that would keep it from working there: https://bugzilla.mozilla.org/show%5Fbug.cgi?id=507361

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文