Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shim does not work in iOS8 UIWebView #161

Closed
ls-jamie-hill opened this issue Sep 3, 2014 · 18 comments
Closed

shim does not work in iOS8 UIWebView #161

ls-jamie-hill opened this issue Sep 3, 2014 · 18 comments

Comments

@ls-jamie-hill
Copy link

I have just tested using this shim in a UIWebView in iOS8 and it does not work. It works fine in iOS7 UIWebView. And while Safari iOS8 actually has indexedDB support now it seems the UIWebView still doesn't. It still supports WebSQL so the shim should still theoretically work as it did in iOS7 but it doesn't. window.indexedDB returns null.

@jmeistrich
Copy link

I just hit this problem myself. It looks like in the UIWebView, window.indexedDB is a readonly property set to null. I think like the solution is to use WKWebView instead of UIWebView on iOS 8.

@ls-jamie-hill
Copy link
Author

OK. Is that something that you've tested as a working solution?

@jmeistrich
Copy link

WKWebView has full indexedDB support so it won't need the shim. We have not yet switched to using WKWebView so we're currently working around the problem in UIWebView by having the shim and our fork of db.js work with an object named '_indexedDB' since 'indexedDB' is readonly. That's not a great general purpose workaround though. I'd love to know if anyone finds a better solution.

@ls-jamie-hill
Copy link
Author

OK, makes sense. I haven't delved into it further, but if that's the case you should be able to determine whether to use UIWebView or WKWebView on the fly based on the iOS version (since you need iOS8 for WKWebView), assuming the interface is the same.

@ls-jamie-hill
Copy link
Author

@jmeistrich how'd you go with your workaround? it seems the readonly indexedDB affects latest Safari too.

@DickvdBrink
Copy link
Collaborator

I did look at this problem yesterday and couln't find a solution.
What I did for now is using shimIndexedDB.open directly instead of indexedDB.open
I know, not a real solution but the problem is a bit harder than I thought it would be.

@kir
Copy link
Contributor

kir commented Sep 18, 2014

Could not be this related to non-working setTimeout after lock/wake up:
http://www.openradar.me/radar?id=5895945212395520 ?
Just a thought.

On 18 September 2014 12:59, Dick van den Brink notifications@github.com
wrote:

I did look at this problem yesterday and couln't find a solution.
What I did for now is using shimIndexedDB.open directly instead of
indexedDB.open
I know, not a real solution but the problem is a bit harder than I thought
it would be.


Reply to this email directly or view it on GitHub
#161 (comment)
.

Kirill (KIR) Maximov
Software Engineer & Starter

Twitter: http://twitter.com/maxkir
Google+ http://gplus.to/maxkir
Skype: maxkir
http://kirblog.idetalk.com | http://checkvist.com |
http://www.jetbrains.com/teamcity

@nolanlawson
Copy link

I filed an issue on WebKit: https://bugs.webkit.org/show_bug.cgi?id=137034

@jmeistrich
Copy link

@jamiejhill The workaround is working out fine. We're using db.js on top of IndexedDB and set it to use _indexedDB instead of window.indexedDB.

@nolanlawson
Copy link

Sure, but existing apps that just use window.indexedDB will be broken...

In any case, Apple confirmed the issue! So hopefully it'll get fixed soon. 🎉

@trevorbest
Copy link

This is working for me:
if (window.indexedDB) {
console.log('Opening Native IndexedDB');
openRequest = window.indexedDB.open(app.dbName,app.dbVersion);
}
else {
console.log('Opening IndexedDB Shimm');
openRequest = window.shimIndexedDB.open(app.dbName,app.dbVersion);
}
I did have some issues opening cursors on an index range but I reverted to an earlier version of the shim and that cured it.

@kberryman
Copy link

Shouldn't Safari in general be added to the poorIndexedDbSupport group due the current bug in the Mac and iOS 8 versions that make it unusable?

http://www.raymondcamden.com/2014/9/25/IndexedDB-on-iOS-8--Broken-Bad

@unclexiao
Copy link

It's a headache for me,I don't know how to fixed it

@nolanlawson
Copy link

In PouchDB, we swallowed our pride and just checked for "Safari" in the user agent. LocalForage and YDN-DB followed suit; you may want to do the same thing. :(

@axemclion
Copy link
Collaborator

Well, I would say lets do it, and check for Safari agent 😢

@unclexiao
Copy link

I had resolved this problem now,but thanks all the same.

if (!window.indexedDB) {
window.indexedDB = window.shimIndexedDB;
}

2014-12-02 2:26 GMT+08:00 Parashuram N notifications@github.com:

Well, I would say lets do it, and check for Safari agent [image: 😢]


Reply to this email directly or view it on GitHub
#161 (comment)
.

@morkeleb
Copy link

I tried to add Safari to the poorBrowsers list.

Turns out that at least in the ios simulator, the window.indexedDB is read only. Which means it throws a TypeError when trying to assign the shim to it.

I caught the TypeError and instead hoped that the code further down in useShim that does a rewrite of the window.indexedDB property would work to use the shim. Alas, it didn't.

So the shim cannot replace the iOS implementation what I can see.

What I did was instead to have the browser check in my own code and use the indexedDBShim for Safari, but handle that in my own code.

It turns out that was 3 lines for the extra check for me and instead of having window.indexedDB I needed to declare my own var indexedDB field in my module that I could switch the implementation for.

@JamesMessinger
Copy link
Collaborator

Closing this issue, since it's actually a WebKit bug. The window.indexedDB variable is read-only, so we can't shim it. Until WebKit fixes the bug, there are two possible workarounds that you can use:

  1. Use window.shimIndexedDB instead of window.indexedDB
    We always add this property to the window object, even if the browser natively supports IndexedDB. This allows you to use the shim instead of the native implementation, which is useful because some native implementations are really buggy (Safari and IE).
  2. Create an indexedDB variable in your closure
    By creating a variable named indexedDB, all the code within that closure will use the variable instead of the window.indexedDB property. For example:
(function() {
    // This works on all browsers, and only uses IndexedDBShim as a final fallback 
    var indexedDB = window.indexedDB || 
                    window.mozIndexedDB ||
                    window.webkitIndexedDB || 
                    window.msIndexedDB || 
                    window.shimIndexedDB;

    // This code will use the native IndexedDB, if it exists, or the shim
    indexedDB.open("MyDatabase", 1);
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests