LocalStorage and the file: protocol are not constant, SQLite gives SECURITY_ERR

Introduction

I am working with RapidWeaver - Mac OS X CMS and does not use a server environment. It has an editor and a preview mode. Preview mode is a Webkit-based visualization tool, and I can use the "Inspect Element", as you usually can with Safari.

I want to save some settings for a toolbar using localStorage or SQLite . I read some information about indexed DB, although I did not find specific implementations on how to use it.

Problems with localStorage

localStorage works fine when I stop in preview mode, when I switch between editor and preview mode, url - location.href - is slightly changed:

file:///private/var/folders/s7/x8y2s0sd27z6kdt2jjdw7c_c0000gn/T/TemporaryItems/RapidWeaver/98970/document-143873968-28/RWDocumentPagePreview/code/styled/index.html file:///private/var/folders/s7/x8y2s0sd27z6kdt2jjdw7c_c0000gn/T/TemporaryItems/RapidWeaver/98970/document-143873968-29/RWDocumentPagePreview/code/styled/index.html 

document-143873968- 28 changes to document-143873968- 29

What I read about localStorage is that it is basically globalStorage [location.hostname] for FireFox. As far as I know, globalStorage is not supported in Safari, so I can not try this.

SQLite issues

When I try to open a database:

 var shortName = 'mydatabase'; var version = '1.0'; var displayName = 'My Important Database'; var maxSize = 65536; // in bytes var db = openDatabase(shortName, version, displayName, maxSize); 

I get this in my console:

 SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent. 

This basically concludes my question, I will be grateful for any answers or comments sincerely.

+3
source share
2 answers

Using the following solution: Implementing the WebView Database Quota Delegate with a few changes, I was able to get it working.

The following delegate method worked for me (a place in your webViewDelegate):

 - (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(id) origin database:(NSString *)databaseIdentifier { static const unsigned long long defaultQuota = 5 * 1024 * 1024; if ([origin respondsToSelector: @selector(setQuota:)]) { [origin performSelector:@selector(setQuota:) withObject:[NSNumber numberWithLongLong: defaultQuota]]; } else { NSLog(@"could not increase quota for %@", defaultQuota); } } 

By default, the database is assigned 0 bytes, which results in an undefined error message. The above method is called after trying to create a database when there is not enough space. Please note that this method is defined in WebUIDelegatePrivate.h ( http://opensource.apple.com/source/WebKit/WebKit-7533.16/mac/WebView/WebUIDelegatePrivate.h ) and use may prevent you from sending your application to the application store Mac

+2
source

localStorage is an html5 mechanism that gives scripts a bit more space than cookies. Safari supports it: http://developer.apple.com/library/safari/ipad/#documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html

I do not know that, if any, the limitations of the path that it should have for files: ///.

Edit: further studying the limitations on the way, I see that what you got should work with Safari, FF recently fixed an error that would not let it work: https://bugzilla.mozilla.org/show%5Fbug. cgi? id = 507361

+1
source

All Articles