I'm submitting a ...
[x] bug report
[ ] feature request
Current behavior:
I'm trying to add Secure Storage plugin to my ionic app following the instructions below:
http://ionicframework.com/docs/native/secure-storage/
I added the plugin to my app's module to the provider section and added the code below to my app.component.ts inside platform.ready()
// Secure Storage
this.secureStorage = new SecureStorage();
this.secureStorage.create('myappstorage')
.then((storage: SecureStorageObject) => {
// Language
storage.get('language')
.then(data => {
console.log('language', data);
translateService.use(data);
this.translateProvider.use(data);
}
);
});
However, I'm getting the following error:
core.es5.js:1020 ERROR Error: Uncaught (in promise): cordova_not_available
at c (polyfills.js:3)
at c (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.es5.js:3881)
at t.invokeTask (polyfills.js:3)
at r.runTask (polyfills.js:3)
at o (polyfills.js:3)
at HTMLDocument.invoke (polyfills.js:3)
Expected behavior:
I expect the plugin to work as described in the official documents
Other information:
I created an issue in the official plugin repo and I was sent here
https://github.com/Crypho/cordova-plugin-secure-storage/issues/131
Any ideas?
How are you testing this plugin? Locally in your browser or in either an emulator or on an actual device? If locally, this plugin will not work.
I get this error as soon as I try ionic serve. If I comment out the code above ionic serve works as expected and my app runs
Correct. That plugin, like many, will NOT work in the browser. You will need to test it an emulator or on-device.
@chrisgriffith I think you misunderstood my issue. Adding the code above is breaking my app as soon as I run ionic serve
Correct. Ionic serve runs your app locally in a browser. That plugin will
NOT work in a browser, you have to run it on a real device or in an
emulator.
On Wed, Sep 20, 2017 at 11:34 AM, Luis Cabrera notifications@github.com
wrote:
@chrisgriffith https://github.com/chrisgriffith I think you
misunderstood my issue. Adding the code above is breaking my app as soon as
I run ionic serve—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ionic-team/ionic-native/issues/1984#issuecomment-330941813,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAgOA5S8DrZRYuF6TlYZdwt1EsEnnKHZks5skVq6gaJpZM4PeQV0
.
@chrisgriffith thank you for taking the time to look into this, and I agree with you that this plugin will NOT work in a browser. However, it should not break my app.
Can try it yourself?
Do I need to wrap it like this to evaluate for plarform? Maybe?
if (platform.is('cordova')) {
... [secure storage code here]
}
That is one option. You could also look at using Ionic Native Mocks (
https://github.com/chrisgriffith/ionic-native-mocks) to fake the plugin in
the browser.
On Wed, Sep 20, 2017 at 12:16 PM, Luis Cabrera notifications@github.com
wrote:
I found this
https://stackoverflow.com/questions/42840951/uncaught-
in-promise-cordova-not-available-in-ionic-2—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ionic-team/ionic-native/issues/1984#issuecomment-330952942,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAgOA18cR7e8sKJT0K2FfDI-YPVgQb02ks5skWR4gaJpZM4PeQV0
.
Ah that's awesome, I'll give it a shot!
I came across the same problem but there is a much easier fix that will allow you to still run it within your browser:
ionic cordova platform add browser
ionic cordova run browser
This will deploy it to your browser and then inject cordova.js into it so that you will be able to use a lot of the plugins that you would otherwise only be able to use with an emulator or on a phone itself. The issue is that there is no live update feature so you will need to rerun after making changes.
Hope this helps.
We do not suggest using Cordova's browser platform for anything other than perhaps testing. Our general advice is to use the Web APIs as much as possible, and only use plug-ins when either the webview on the mobile device does not support the action or the action is very mobile specific (integrating with iOS HealthKit, setting the Android status bar color, stuff like that).
Refer to this site for data on what can be done via Web APIs: https://whatwebcando.today/
For PWAs, we suggest not using cordova.js at all.
If your app needs to support running as a native mobile app as well as a PWA / web-app, then we suggest detecting how the app is currently running and then using the plugin (if applicable) in mobile and some other appropriate method when on web as per the plugins section of this document: https://ionicframework.com/docs/developer-resources/desktop-support/
Can someone remove Browser from the list of supported platforms if it is not actually supported under best practices (in the case of PWA's).
Most helpful comment
I came across the same problem but there is a much easier fix that will allow you to still run it within your browser:
ionic cordova platform add browserionic cordova run browserThis will deploy it to your browser and then inject cordova.js into it so that you will be able to use a lot of the plugins that you would otherwise only be able to use with an emulator or on a phone itself. The issue is that there is no live update feature so you will need to rerun after making changes.
Hope this helps.