Hello @mauri870. Thanks for reporting this issue regarding SharedWorker
in WKWebView
on iOS 16.1, and for the bug report.
While our engineers work on a long-term solution, the suggested workaround is to disable SharedWorker
s for the web site you're loading.
You can either do this in your web source, if you control it, or in your native app, if you are loading arbitrary web sites.
As an example, the sample code in Code Listing 1 disables SharedWorker
s when loading a page in WKWebView
, by injecting a script using WKUserScript
.
Code Listing 1.
func makeViewConfiguration() -> WKWebViewConfiguration
{
let configuration = WKWebViewConfiguration()
let dropSharedWorkersScript = WKUserScript(source: "delete window.SharedWorker;", injectionTime: WKUserScriptInjectionTime.atDocumentStart, forMainFrameOnly: false)
configuration.userContentController.addUserScript(dropSharedWorkersScript)
return configuration
}
var view = WKWebView(frame: CGRect(x: 0, y: 0, width: 400, height: 400), configuration: makeViewConfiguration())
Important: This code was minimally tested to ensure it builds, runs, injects the script, and disables SharedWorker
s. It may require changes for your specific use.
You can read more about this issue on the WebKit GitHub page.
—Jason.