Home > Software engineering >  Releasing WKNavigationAction subclass crashes on iOS 15
Releasing WKNavigationAction subclass crashes on iOS 15

Time:10-27

For unit testing I have subclassed WKNavigationAction. It's a common practice and can be found across the internet and in big SDKs, too.

On iOS 15 releasing an instance of it leads to a crash inside WebKit.

Stacktrace:

Thread 1 Queue : com.apple.main-thread (serial)
#0  0x0000000130d8b702 in WTF::RunLoop::dispatch(WTF::Function<void ()>&&) ()
#1  0x0000000134ed41e4 in WebCoreObjCScheduleDeallocateOnMainRunLoop(objc_class*, objc_object*) ()
#2  0x000000011290711d in -[WKNavigationAction dealloc] ()
#3  0x000000010cf2f9f7 in objc_object::sidetable_release(bool, bool) ()

Example Playground:

import WebKit

class MockNavigationAction: WKNavigationAction {}

var navigationAction: WKNavigationAction? = MockNavigationAction()

navigationAction = nil

Suggestions about how to solve this are very appreciated.

CodePudding user response:

Seems like a WebKit bug, you need to kickstart the framework, otherwise the deallocation fails.

Just create a dummy webview sometimes during the app/tests startup:

_ = WKWebView()

This workaround will fix the crash, as creating a WKWebView will launch the WebKit engine, and will likely initialize the values that were causing the crash.

Theoretically, you should not need the above code, as you'll anyway have to pass a WKWebView instance to the delegate methods.

  • Related