Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dom Exception 18 in javascript/html5 when trying to access local storage

I have the following html that tries to set one key in local storage.

<!DOCTYPE html>
<html>
<head>
  <title>Test</title>
  <script>
  document.addEventListener('DOMContentLoaded', loaded, false);
  function loaded(){
    try {
      window.localStorage.setItem("Test", "SetItemValue");
      document.getElementById("test").innerHTML = "Test OK";
    } catch (err) {
      document.getElementById("test").innerHTML = "Test FAIL<br>" + err.message;
    }
  }
  </script>
</head>
<body>
  <div id="test">Testing...</div>
</body>
</html>

On one single iPhone5 this causes the following exception.

Test FAIL
SecurityError: DOM Exception 18

Other iPhones tested (three others) with the same iOs-version (7.0.2) works.

I have tested the above page from both a https://x.y.domain.tld and a http://x.domain.tld with the same exception.

Other questions concerning "DOM Exception 18" seem to be about security settings when eg. testing on localhost but linking in remote content over https. But this is a simple html page that simply tries to access local storage.

like image 831
mnsc Avatar asked Nov 11 '22 20:11

mnsc


2 Answers

I read somewhere that if cookies are blocked, the DOM Exception 18 error shows up when setting localStorage. I was able to reproduce the error (not sure if I reproduced the issue, per se) on a simulator iPhone 5 (w/ iOS7) by going to the Settings, then for Safari, "Block Cookies" always. Don't know if that's how your iPhone 5 is configured though...

like image 196
C F Avatar answered Nov 14 '22 22:11

C F


Problem was solved. It was revealed that the client (the errant phone was a client phone) uses a company-wide security platform installed on their iPhones. That platform has a separate web browser that must be used to enable every Javascript feature. The end user with the phone didn't know this so he used Safari that somehow is crippled when this platform is active. So the solution was to use the right application for browsing.

The platform was http://www.mobileiron.com/ and the secure browser is called Web@Work

like image 45
mnsc Avatar answered Nov 14 '22 22:11

mnsc