SecureStorage does not work in browser


#1

In the docs the browser is listed as supported platform of SecureStorage.

See:

But when I add the following code to my app, it won’t work anymore and an error is thrown:
Can't find variable : Cordova

let secureStorage: SecureStorage = new SecureStorage();
secureStorage.create('my_store_name')
 .then(
   () => console.log('Storage is ready!'),
   error => console.log(error)
);

Are the docs wrong or is SecureStorage broken?


#2

How are you running it in the browser? With ionic serve or with ionic run browser?


#3
ionic serve

The other command isn’t mentioned in the docs, as far as I can see.


#4

That explains it then. Cordova and therefore Cordova plugins are not available when running with ionic serve.

When a Cordova plugin says it supports the “browser” that really means the Cordova browser platform. You can add it to your project like any other platform:

ionic platform add browser
ionic run browser

#5

Thank you very much for the clarification!