I have an Android webview that I think has everything you need to access and use localStorage, but when I try to use local storage, I see a "Access Denied" error on the console. Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
Can anyone spot the problem?
JavaScript Code:
function localStorageTest() { // Check browser support if (typeof(Storage) != "undefined") { // Store localStorage.setItem("lastname", "Smith"); // Retrieve document.getElementById("console").innerHTML = localStorage.getItem("lastname"); } else { document.getElementById("console").innerHTML = "Sorry, your browser does not support Web Storage..."; } }
Here is the Android code:
// Enable javascript WebSettings settings = getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); // Create database folder String databasePath = getContext().getDir("databases", Context.MODE_PRIVATE).getPath(); getSettings().setDatabasePath(databasePath); getContext().getPackageName() + "/databases/"); settings.setAppCacheEnabled(true); settings.setSaveFormData(true);; settings.setLoadWithOverviewMode(true); settings.setSaveFormData(true);
source share