在Firefox Web扩展中使用数据库 [英] Use database in the Firefox web extension
问题描述
我想在Firefox Web扩展中使用某些数据库,我已经找到
I want to use some database in my Firefox web extension, I already found this, but it's just a storage for key-value pairs.
那么如何在Firefox Web扩展中使用数据库?
So how can I use database in the Firefox web extension?
推荐答案
You can use the IndexedDB Web API: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
有一个使用它的示例扩展 ,尽管它使用的是库.最好查看常规使用IndexedDB 例子.
There's a sample extension that uses it, though it's using a library. It might be better to look at general Using IndexedDB examples.
您可能想声明"unlimitedStorage"
权限;在Chrome中,它取消了5MB的大小限制,而在Firefox中,它显然
You probably want to declare "unlimitedStorage"
permission; in Chrome, it lifts the 5MB restriction on size, while on Firefox it apparently bypasses a user prompt.
请注意,IndexedDB是基于源的,因此您的内容脚本(从技术上来说,其来源是运行它们的页面)将无法直接访问它;您将需要依靠消息传递来让后台页面代理"访问.
Note that IndexedDB is per-origin, so your content scripts (whose origin is technically the page they are running in) won't be able to access it directly; you'll need to rely on Messaging to let the background page "proxy" the access.
这篇关于在Firefox Web扩展中使用数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!