1

Hit an issue with our mobile app (home screen safari app) in that it started reporting since iOS 13 that there was no html5 database support.

It tries to detect support for WebSQL with the following code:

function getDBType() {
  if (typeof window.openDatabase == "function") {
    return "WebSQL";
  }
  return "IndexedDB";
}

Unfortunately this is reporting that, despite WebSQL being removed from Safari 13, WebSQL is available, only to fall over with an exception later when it tries to call window.openDatabase().

On closer inspection it seems that something weird is happening:

(typeof window.openDatabase == "function") == true
(typeof window.openDatabase == "undefined") == true
(typeof window.openDatabase == "randomstring") == false
window.openDatabase == [object Function]  /* not native function */

Test Page: http://locutus.sorcerer.co.uk/demo/safari-openDatabase.html

So the question is, how to properly test for WebSQL support that will work on safari 13?

One thought is to do the following to detect Safari 13's lack of support (with comment explaining the seeming pointless test)

if (typeof window.openDatabase == "function" && typeof window.openDatabase != "undefined") {
  return "WebSQL";
}

Side Note: It is possible to enable WebSQL in Safari 13 on iOS is settings, Safari -> Advanced -> Experimental Features -> disable the 'Disable WebSQL' option. Only works in Safari app though, home screen safari apps still don't get WebSQL support.

Austin France
  • 2,381
  • 4
  • 25
  • 37

1 Answers1

3

Our code uses if (!window.openDatabase) throw 'No WebSQL support'; and that seems to be enough to detect the disabled setting on iOS13

EionRobb
  • 532
  • 5
  • 13
  • Ah, so simple. Yes that works. I am now using `app.platform.hasWebSQL = !!window.openDatabase` – Austin France Sep 30 '19 at 11:21
  • Looks like this was done intentionally for this kind of detection as part of the disabling of WebSQL https://trac.webkit.org/changeset/246707/webkit/ – EionRobb Sep 30 '19 at 21:24
  • 1
    And so by avoiding breaking websites that subvert the API for private browsing detection, they broke websites that made a reasonable attempt to detect the presence of the API. Thanks for the link btw :) – Austin France Oct 02 '19 at 08:54
  • https://bugs.webkit.org/show_bug.cgi?id=202485 has been logged to addres the `typeof window.openDatabase == "function"` is true issue, that test should be false. – Austin France Oct 02 '19 at 22:17