简体   繁体   中英

Database in Chrome Packaged Apps

I have been trying to implement a local database in a packaged app which does not seem to be working.

I tried using PouchDB which is a layer over IndexedDB and then I tried using the native IndexedDB API. Both don't work and I receive the same message: An attempt was made to break through the security policy of the user agent.

I Googled about database methods for packaged apps but only found info on how to use the FileSystem API .

Any links pointing towards database implementation on Chrome packaged apps will be really helpful (or just let me know if I am doing something wrong).

Sample code to initiate IndexedDB:

idbSupported = false;
db = '';    
if("indexedDB" in window) {
    idbSupported = true;
}
if(idbSupported) {
    var openRequest = indexedDB.open("test",1);

    openRequest.onupgradeneeded = function(e) {
        console.log("Upgrading...");
    }

    openRequest.onsuccess = function(e) {
        console.log("Success!");
        db = e.target.result;
    }

    openRequest.onerror = function(e) {
        console.log("Error");
        console.dir(e);
    }
}

Permissions inside manifest file

"permissions": ["http://*/*", "https://*/*","storage","fileSystem"]

也许尝试以下权限:

"permissions": ["storage", "<all_urls>", "unlimitedStorage"]

Perhaps you were using some earlier version of Chrome, but I am able to use IndexedDB without any permissions at all, as it's not a Chrome Platform API. My app is a normal Chrome App -- no additional sandboxing. I didn't understand your comment, so maybe you have it working. If so, it would be nice to post the answer and mark it so this thread is properly wrapped up.

You have to provide unlimited storage for inside the manifest.json

To see a complete offline implementation ( local) of a chrome indexeddb app, based on the HTML5Rocks to do article,check out this github project

https://github.com/abdullahc/Indexeddb-Chrome-App

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM