Monaca Onsen UI Discord Chat Github Repo

Need to test Cordova SQL plugin in Chrome dev setting.



  • SQL DB is integral to the functionality of my app, but I don’t want to have to “compile” and test on mobile every time I need to check something. Is there a mechanism by which to import/require Cordova DB plugins for use/test in browser dev?


  • Onsen UI

    This is dependent on the plugin itself. Cordova plugins can support the browser platform to allow for testing like this. I presume you are using cordova-sqlite-storage? From what I can see, that doesn’t currently have the browser platform. However, it looks like it could be on the way soon, according to their next release plan.



  • Grrrr. Apparently they’re going to “accomplish” this by using sql.js which isn’t even persistent. Any suggestions on persisting tokens/credentials for web API access @asialgearoid? Currently, I’m trying localStorage, but that seems to get wiped.


  • Onsen UI

    localStorage can get cleared by mobile OSs, especially on iOS, when memory is running low.

    I usually create a generic Storage JS class in my app, so I can abstract away the actual implementation of the storage. It has basic get and set functionality. In there you can check whether you are in browser or on device. Not ideal, but at least you can test it.

    class Storage {
      get() {
        if(isCordova) {
          // save in SQL
        } else {
          // save in localStorage
        }
      }
    
      ...
    }
    

    Perhaps you could try WebSQL instead of localStorage for in browser, as long as it’s just for development? It’s deprecated now, so don’t use it in production, but if you’re just testing in Chrome, it would work.