开发者

How can you create a local JavaScript database tied to a Safari-5 extension?

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 开发者_如何学CImportant 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜