LoginSignup
0
0

More than 1 year has passed since last update.

Safari 14.1.1(macOS 及び iOS 14.6)で初回 indexedDB.openが正常に動作しない問題

Last updated at Posted at 2021-07-09

問題

WKWebView上にWebアプリケーションの一部画面を表示する機能を作成しており、indexedDB上のデータ取得が、特定条件で正常に動作しないことに気が付きました。

原因

最新のSafari(MacOSおよびiOS 14.6の14.1.1)で初めてロードしたときに indexedDBのopen(データベースを開くリクエスト)が永遠にpanding状態でリクエストが消失する不具合が、WebKitにあるようです。
indexedDB.open() sometimes hangs forever in pending state on first page load in iOS 14.6 / WebKit Bugzilla

対策

有志によってnpm/safari-14-idb-fixが用意されているようですが、自環境では解消出来ず、WKUserScriptを利用して消失しても問題ないリクエストを事前に実行することで解消しました。

let configuration = WKWebViewConfiguration()
let userContentController = WKUserContentController()
let userScript = WKUserScript(source: "window.indexedDB.open(\"dummy\", 1);", injectionTime: .atDocumentStart, forMainFrameOnly: false)
userContentController.addUserScript(userScript)
configuration.userContentController = userContentController
webView = WKWebView(frame: .zero, configuration: configuration)

参考

https://developer.mozilla.org/ja/docs/Web/API/IndexedDB_API/Using_IndexedDB
https://bugs.webkit.org/show_bug.cgi?id=226547
https://www.npmjs.com/package/safari-14-idb-fix
https://bugs.webkit.org/show_bug.cgi?id=225344
https://gist.github.com/pesterhazy/4de96193af89a6dd5ce682ce2adff49a#bugs-bugs-bugs-safari

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0