代码之家  ›  专栏  ›  技术社区  ›  googletorp

如何创建绑定到Safari-5扩展的本地javascript数据库?

  •  1
  • googletorp  · 技术社区  · 14 年前

    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?

    1 回复  |  直到 14 年前
        1
  •  2
  •   zneak    14 年前

    The correct way would be to do it from the global page instead of from an injected script. Problem is, it won't work.

    从全局页创建脱机数据库将触发 SECURITY_ERR . 这是一个已知的bug,应该在下一个版本中修复。

    所以, 马上 没有办法。

    编辑 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.

    推荐文章