Uncaught(in Promise) DOM Exception


What is DOM Exception:

The DOMException represents an abnormal event happening when a method or a property is used.

Error Properties:

Returns a DOMString that contains one of the string associated with an error constant.

Root Cause for the problem:
  1. DOM Exception error occurs for the hybrid apps once the google webview has been updated to 66.0.3359.126
  2. Because on the update the apps which is running in Android OS Version of 5.1 and 6.0 doesn’t allows the hybrid apps to work
  3. The problem arise because the local forage used in the application doesn’t use the catch block which cause the problem
Example code:

      localforage.setItem('user', data).then(function (data) {
          vm.userData = data;
     });    

Which will return to DOM Exception whereas if we use the catch block for it then the DOM Exception error will not occur.

Correct Code:

localforage.setItem('key', 'value').then(function () {
    return localforage.getItem('key');
 }).then(function (value) {
     // we got our value
 }).catch(function (err) {
    // we got an error
 });

It is better to use localStorage instead of localForage

Difference between localStorage and localForage:
  1. LocalStorage API is synchronous and accepts simple key value strings.
  2. LocalForage leverage this simple interface with Promises to get/set values and gives the ability to store more than converted strings as data.
  3. If you are familiar with the logic of LocalStorage and you are experimenting with something new I suggest you give it a try.

Comments

Popular posts from this blog

Google play Impersonation and Intellectual Property

Creating Gauge chart in React Native

React Native Splash Screen