@UIApplicationMain in AppDelegate.swift crash

When I visit "ksl.com", the site loads and after few seconds, the entire browser closes (our app crash). I'm using Xcode 13.4. I've been digging into the code and did several ways but still my app crash. Can someone help me to fix this issue?

Please see my crash log details.

    frame #0: 0x000000018fc9496c WebCore`JSC::JSValue WebCore::wrap<WebCore::DOMException>(JSC::JSGlobalObject*, WebCore::JSDOMGlobalObject*, WebCore::DOMException&) + 24
    frame #1: 0x0000000190882dd8 WebCore`WebCore::CloneDeserializer::readTerminal() + 292
    frame #2: 0x000000019088c728 WebCore`WebCore::SerializedScriptValue::deserialize(JSC::JSGlobalObject&, JSC::JSGlobalObject*, WTF::Vector<WTF::RefPtr<WebCore::MessagePort, WTF::RawPtrTraits<WebCore::MessagePort>, WTF::DefaultRefDerefTraits<WebCore::MessagePort> >, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&, WTF::Vector<WTF::String, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&, WTF::Vector<WTF::String, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&, WebCore::SerializationErrorMode) + 6172
    frame #3: 0x00000001908758d0 WebCore`WebCore::SerializedScriptValue::deserialize(JSC::JSGlobalObject&, JSC::JSGlobalObject*, WebCore::SerializationErrorMode) + 52
    frame #4: 0x000000019088d4bc WebCore`WebCore::SerializedScriptValue::deserialize(OpaqueJSContext const*, OpaqueJSValue const**) + 68
    frame #5: 0x000000018f1f6ff8 WebKit`API::SerializedScriptValue::deserialize(WebCore::SerializedScriptValue&, OpaqueJSValue const**) + 72
    frame #6: 0x000000018f269330 WebKit`ScriptMessageHandlerDelegate::didPostMessage(WebKit::WebPageProxy&, WebKit::FrameInfoData&&, API::ContentWorld&, WebCore::SerializedScriptValue&) + 132
    frame #7: 0x000000018f5b0ca0 WebKit`WebKit::WebUserContentControllerProxy::didPostMessage(WTF::ObjectIdentifier<WebKit::WebPageProxyIdentifierType>, WebKit::FrameInfoData&&, unsigned long long, WTF::Span<unsigned char const, 18446744073709551615ul> const&, WTF::CompletionHandler<void (WTF::Span<unsigned char const, 18446744073709551615ul> const&, WTF::String const&)>&&) + 616
    frame #8: 0x000000018f8ba054 WebKit`void IPC::handleMessageAsync<Messages::WebUserContentControllerProxy::DidPostMessage, WebKit::WebUserContentControllerProxy, void (WebKit::WebUserContentControllerProxy::*)(WTF::ObjectIdentifier<WebKit::WebPageProxyIdentifierType>, WebKit::FrameInfoData&&, unsigned long long, WTF::Span<unsigned char const, 18446744073709551615ul> const&, WTF::CompletionHandler<void (WTF::Span<unsigned char const, 18446744073709551615ul> const&, WTF::String const&)>&&)>(IPC::Connection&, IPC::Decoder&, WebKit::WebUserContentControllerProxy*, void (WebKit::WebUserContentControllerProxy::*)(WTF::ObjectIdentifier<WebKit::WebPageProxyIdentifierType>, WebKit::FrameInfoData&&, unsigned long long, WTF::Span<unsigned char const, 18446744073709551615ul> const&, WTF::CompletionHandler<void (WTF::Span<unsigned char const, 18446744073709551615ul> const&, WTF::String const&)>&&)) + 2376
    frame #9: 0x000000018f8b96f8 WebKit`WebKit::WebUserContentControllerProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 76
    frame #10: 0x000000018f2e19bc WebKit`IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 440
    frame #11: 0x000000018f5150dc WebKit`WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 36
    frame #12: 0x000000018f2d5c04 WebKit`IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 256
    frame #13: 0x000000018f2d5468 WebKit`IPC::Connection::dispatchIncomingMessages() + 492
    frame #14: 0x000000018b82efc4 JavaScriptCore`WTF::RunLoop::performWork() + 372
    frame #15: 0x000000018b82fb40 JavaScriptCore`WTF::RunLoop::performWork(void*) + 32
    frame #16: 0x00000001810744ec CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame #17: 0x000000018108461c CoreFoundation`__CFRunLoopDoSource0 + 204
    frame #18: 0x0000000180fc6824 CoreFoundation`__CFRunLoopDoSources0 + 256
    frame #19: 0x0000000180fcbef8 CoreFoundation`__CFRunLoopRun + 768
    frame #20: 0x0000000180fdf240 CoreFoundation`CFRunLoopRunSpecific + 572
    frame #21: 0x00000001a1ad5988 GraphicsServices`GSEventRunModal + 160
    frame #22: 0x00000001837df41c UIKitCore`-[UIApplication _run] + 1080
    frame #23: 0x0000000183578b88 UIKitCore`UIApplicationMain + 336
  * frame #24: 0x000000010287b458 Ever Accountable`main at AppDelegate.swift:13:7
    frame #25: 0x0000000102e6c3d0 dyld`start + 444

Here's my AppDelegate.swift code:

import StoreKit

import GoogleSignIn
import Sentry

import GRDB

var dbQueue: DatabaseQueue!

@UIApplicationMain
class AppDelegate: UIResponder,
          UIApplicationDelegate,
          GIDSignInDelegate {
   
  var window: UIWindow?
   
  var googleSignInCallback:((GIDGoogleUser)->())?
  var isSubscriptionGood: Bool = false

  func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    Client.shared = try? Client(dsn: SENTRY.dsn)
    try? Client.shared?.startCrashHandler()

    try! setupDatabase(application)

    if !AppSetting.get().importFromPreviousAppVersionDone {

      defer {

        var setting = AppSetting.get()
        setting.importFromPreviousAppVersionDone = true
        try? dbQueue.write { db in try setting.update(db) }
      }

      // ..... code here
    }
       
    window = UIWindow(frame: UIScreen.main.bounds)
    let viewController = ViewController()
    viewController.initialize()
    window!.rootViewController = viewController
    window!.makeKeyAndVisible()
     
    IAPManager.shared.startObserving()
    IAPManager.shared.loadProducts()

    return true
  }

  // ....... more code
}

I got the same issue "JSC::JSValue WebCore::wrapWebCore::DOMException(JSC::JSGlobalObject*, WebCore::JSDOMGlobalObject*, WebCore::DOMException&) ()" when I tried to inject this kind of code to userContentController, it was used to capture log from console of the web view.

.... let source = "function captureLog(msg) { window.webkit.messageHandlers.logHandler.postMessage(msg); } window.console.log = captureLog; console.log("injected");"

    let script = WKUserScript(source: source, injectionTime: .atDocumentEnd, forMainFrameOnly: false)     webView.configuration.userContentController.addUserScript(script) .....     webView.configuration.userContentController.add(self, name: "logHandler") ....

Then I removed the function, and the crash was gone. (already tried to set the web view delegate to nil)

&#64;UIApplicationMain in AppDelegate.swift crash
 
 
Q