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:
- DOM Exception error occurs for the hybrid apps once the google webview has been updated to 66.0.3359.126
- 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
- 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:
- LocalStorage API is synchronous and accepts simple key value strings.
- LocalForage leverage this simple interface with Promises to get/set values and gives the ability to store more than converted strings as data.
- If you are familiar with the logic of LocalStorage and you are experimenting with something new I suggest you give it a try.
Comments
Post a Comment