PouchDB runs great in Chrome packaged apps. Here's how to get started.
To use PouchDB in your Chrome app, just download pouchdb.js and include it in your index.html
:
<script src="path/to/pouchdb.js"></script>
Now PouchDB
is available as a global variable. So you can create a new PouchDB:
var db = new PouchDB('mydb');
Note that only the IndexedDB adapter (i.e. the default adapter) is supported, because Chrome apps disallow WebSQL.
By default, the query()
API will not work in Chrome apps, because PouchDB needs to use eval()
, which is disallowed by Chrome apps' Content Security Policy (CSP).
You could modify the CSP, e.g. by adding "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
to the manifest.json
, but then your app has to run in a sandbox, which is probably not what you want.
To work around this problem, you have a few options:
- Use the pouchdb-find plugin, which is a newer API designed to replace
query()
, and which does not useeval()
. - Use the noeval plugin, which tries to mimic as much of the
query()
API as possible without usingeval()
.
Both plugins can be installed by simply adding the script tag to your index.html
. E.g. for pouchdb-find
:
<script src="path/to/pouchdb.js"></script>
<script src="path/to/pouchdb.find.js"></script>
Another option is to simply not use the query()
API, and to use allDocs()
instead. Instructions for this technique can be found in the PouchDB pro tips (tip #7).
With filtered replication, filter functions inside of design documents are not supported, again because of the eval()
limitation. Luckily you can still use doc_ids
, ad-hoc filter functions, and server-side filtering.