如何创建与 Safari-5 扩展绑定的本地 JavaScript 数据库?
我正在尝试创建一个小型 safari 扩展,主要是为了它的乐趣并看看你可以做什么等。
无论如何,我正在考虑将我的扩展的一些数据存储在本地数据库中,所以我总是将它放在哪里我需要它,跨页面加载。
我在 google 上搜索了一下,从 Safari 参考库中找到了这个片段,它将创建一个 JavaScript 数据库:
var shortName = 'mydatabase';
var version = '1.0';
var displayName = 'My Important Database';
var maxSize = 65536; // in bytes
var db = openDatabase(shortName, version, displayName, maxSize);
这工作得很好,并且创建了我想要的数据库。唯一的问题是,该数据库是特定于域的,因此我创建数据库的脚本将为每个访问的域创建一个数据库,这并不是我想要的。
那么,如果可能的话,如何创建一个可以分配给 safari 扩展的本地存储数据库,以便它可以在所有域上使用?
I was playing around trying to create a small safari extension, most for the fun of it and to see what you could do etc.
Anyways I was thinking about storing some data for my extension in a local database, so I always would have it where I needed it, across page loads.
I searched a bit on google and found this snippet from the Safari Reference Library, that will create a JavaScript 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);
This works pretty well and creates the database like I wanted. The only thing is, that this database is domain specific, so my script creating the database will create a database for each domain visited, which wasn't exactly what I wanted.
So how can you, if possible, create a local storage database, that can be assigned to an safari extension, so it will be available on all domains?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的方法是从全局页面而不是从注入的脚本中执行此操作。问题是,它不会起作用。
从全局页面创建脱机数据库会触发
SECURITY_ERR
。这是一个已知的错误,应该在下一版本中修复。所以,现在,没有办法做到这一点。
编辑 正如 Brian 指出的,此问题从 Safari 5.0.3 开始已得到修复。您必须在扩展构建器中指定数据库大小配额,然后它应该可以工作。
The correct way would be to do it from the global page instead of from an injected script. Problem is, it won't work.
Creating an offline database from a global page triggers a
SECURITY_ERR
. It is a known bug, and it should be fixed in the next release.So, right now, there's no way to do it.
EDIT As Brian points out, this issue is fixed as of Safari 5.0.3. You have to specify a database size quota in Extension builder, and then it should work.