KevinnZou / compose-webview-multiplatform

WebView for JetBrains Compose Multiplatform
https://kevinnzou.github.io/compose-webview-multiplatform/
Apache License 2.0
497 stars 64 forks source link

Webview crashing on iOS when loading HTML data #149

Closed msasikanth closed 5 months ago

msasikanth commented 5 months ago

Hi, I updated to the latest version 1.9.6 and the webview has suddenly started to crash on iOS

My current setup looks like this

val navigator = rememberWebViewNavigator()
val jsBridge = rememberWebViewJsBridge()
val webViewState = rememberWebViewStateWithHTMLData(htmlTemplate)

webViewState.webSettings.apply {
  this.supportZoom = false
}

WebView(
  modifier = Modifier.fillMaxSize(),
  state = webViewState,
  navigator = navigator,
  webViewJsBridge = jsBridge,
  captureBackPresses = false,
)
Uncaught Kotlin exception: kotlin.NumberFormatException
    at 0   Twine (Debug)                       0x10085e39f        kfun:kotlin.Throwable#<init>(){} + 95 
    at 1   Twine (Debug)                       0x1008575d7        kfun:kotlin.Exception#<init>(){} + 87 
    at 2   Twine (Debug)                       0x1008577f7        kfun:kotlin.RuntimeException#<init>(){} + 87 
    at 3   Twine (Debug)                       0x100857bff        kfun:kotlin.IllegalArgumentException#<init>(){} + 87 
    at 4   Twine (Debug)                       0x100858927        kfun:kotlin.NumberFormatException#<init>(){} + 87 
    at 5   Twine (Debug)                       0x1008771f7        kfun:kotlin.native.internal.FloatingPointParser.initialParse#internal + 4043 
    at 6   Twine (Debug)                       0x100874f97        kfun:kotlin.native.internal.FloatingPointParser#parseDouble(kotlin.String){}kotlin.Double + 1515 
    at 7   Twine (Debug)                       0x100898ebb        kfun:kotlin.text#toDouble__at__kotlin.String(){}kotlin.Double + 151 
    at 8   Twine (Debug)                       0x10213db8b        kfun:com.multiplatform.webview.web.WKNavigationDelegate#objc:webView:didFinishNavigation: + 1555 
    at 9   Twine (Debug)                       0x10213f367        _636f6d706f73652d776562766965772d6d756c7469706c6174666f726d3a776562766965772f55736572732f6b6576696e7a6f752f50726f6a6563742f434d4d2f636f6d706f73652d776562766965772d6d756c7469706c6174666f726d2f776562766965772f7372632f696f734d61696e2f6b6f746c696e2f636f6d2f6d756c7469706c6174666f726d2f776562766965772f7765622f574b4e617669676174696f6e44656c65676174652e6b74_knbridge37 + 235 
    at 10  WebKit                              0x1b15c5e67        <redacted> + 175 
    at 11  WebKit                              0x1b17934df        <redacted> + 1063 
    at 12  WebKit                              0x1b1c41feb        <redacted> + 12399 
    at 13  WebKit                              0x1b1d58967        <redacted> + 263 
    at 14  WebKit                              0x1b180116b        <redacted> + 43 
    at 15  WebKit                              0x1b1d539cf        <redacted> + 323 
    at 16  WebKit                              0x1b1d53e57        <redacted> + 555 
    at 17  JavaScriptCore                      0x1b1fa0d43        <redacted> + 203 
    at 18  JavaScriptCore                      0x1b1fa1c6b        <redacted> + 35 
    at 19  CoreFoundation                      0x19bf1562b        <redacted> + 27 
    at 20  CoreFoundation                      0x19bf148a7        <redacted> + 175 
    at 21  CoreFoundation                      0x19bf13057        <redacted> + 243 
    at 22  CoreFoundation                      0x19bf11d87        <redacted> + 827 
    at 23  CoreFoundation                      0x19bf11967        CFRunLoopRunSpecific + 607 
    at 24  GraphicsServices                    0x1e02074df        GSEventRunModal + 163 
    at 25  UIKitCore                           0x19e384edb        <redacted> + 887 
    at 26  UIKitCore                           0x19e384517        UIApplicationMain + 339 
    at 27  SwiftUI                             0x1a0d4b85f        <redacted> + 599 
    at 28  SwiftUI                             0x1a0d4b6a7        <redacted> + 159 
    at 29  SwiftUI                             0x1a09679fb        <redacted> + 363 
    at 30  Twine (Debug)                       0x10021b2f3        $s13Twine__Debug_6iOSAppV5$mainyyFZ + 39 
    at 31  Twine (Debug)                       0x10021b6bf        main + 11 
    at 32  dyld                                0x1bf432d83        <redacted> + 2239 
Type: stdio
KevinnZou commented 5 months ago

@msasikanth It seems that the NumberFormatException is caused by the toDouble method in the following code added in version 1.9.6. However, it is strange to have a NumberFormatException here, since scrollOffset is just a map of Int.

webView.scrollView.setContentOffset(
    CGPointMake(
        x = state.scrollOffset.first.toDouble(),
        y = state.scrollOffset.second.toDouble(),
    ),
    true,
)

I am unable to reproduce this exception on my end. Does your web page contain any operations on the scroll position? Could you try testing this on a simple HTML page?

msasikanth commented 5 months ago

I tried it with my website link: https://sasikanth.dev/dev-log-3/, but it's failing. I am not doing anything fancy with that šŸ¤”

KevinnZou commented 5 months ago

@msasikanth what's the version of your ios device? Is the exception still the NumberFormatException for website link? It still works well on my device(ip15PM 17.4).

msasikanth commented 5 months ago

@msasikanth what's the version of your ios device? Is the exception still the NumberFormatException for website link? It still works well on my device(ip15PM 17.4).

Yep, I tried it on iPhone 15 Pro (17.4.1). All the issue reports from my project are also from this version across different models.

The project I am having issues with is open source in case you want a project to reproduce the issue. https://github.com/msasikanth/twine

If I revert the 1.9.6 update, everything is working fine FWIW.

KevinnZou commented 5 months ago

@msasikanth Thanks for the information! So, both the URL and HTML are not functioning properly in version 1.9.6 of your project?

msasikanth commented 5 months ago

Yes. I tested with a sample URL, but I primarily load HTML strings in my project and so far I only received this issue on device versions 17.4.1

KevinnZou commented 5 months ago

@msasikanth That's weird, considering that the code responsible for causing this issue should not have been executed for version 15 or higher. Its purpose is to restore the scroll position for iOS devices running version 15 or lower, which do not support interactionState. Do you happen to have the stacktrace for the 17.4.1 device?

msasikanth commented 5 months ago

Yeah, it's the same as what I posted. Here is what I received from crash reporting

CrashReporter Key: 
Hardware Model:     iPhone15,2
Process:            Twine
Identifier:         dev.sasikanth.rss.reader
Version:            1.40.0
Role:               Foreground
OS Version:         iOS 17.4.1

kotlin.NumberFormatException: 

0  Twine +0x203a4           kfun:kotlin.native.internal.FloatingPointParser.initialParse#internal (FloatingPointParser.kt)
1  Twine +0x1ef40           <inlined-out:parse> (FloatingPointParser.kt:134:20)
2  Twine +0xd76944          _636f6d706f73652d776562766965772d6d756c7469706c6174666f726d3a776562766965772f55736572732f6b6576696e7a6f752f50726f6a6563742f434d4d2f636f6d706f73652d776562766965772d6d756c7469706c6174666f726d2f776562766965772f7372632f696f734d61696e2f6b6f746c696e2f636f6d2f6d756c7469706c6174666f726d2f776562766965772f7765622f574b4e617669676174696f6e44656c65676174652e6b74_kncfun38
3  WebKit +0x55ae64         WebKit::NavigationState::NavigationClient::didFinishNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*)
4  WebKit +0x7284dc         WebKit::WebPageProxy::didFinishLoadForFrame(WebCore::ProcessQualified<WTF::ObjectIdentifierGeneric<WebCore::FrameIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits> >, WebKit::FrameInfoData&&, WebCore::ResourceRequest&&, unsigned long long, WebKit::UserData const&)
5  WebKit +0xbd6fe8         WebKit::WebPageProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&)
6  WebKit +0xced964         IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&)
7  WebKit +0x796168         WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&)
8  WebKit +0xce89cc         IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >)
9  WebKit +0xce8e54         IPC::Connection::dispatchIncomingMessages()
10 JavaScriptCore +0x58d40  WTF::RunLoop::performWork()
11 JavaScriptCore +0x59c68  WTF::RunLoop::performWork(void*)
12 CoreFoundation +0x37628  ___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
13 CoreFoundation +0x368a4  ___CFRunLoopDoSource0
14 CoreFoundation +0x35054  ___CFRunLoopDoSources0
15 CoreFoundation +0x33d84  ___CFRunLoopRun
16 CoreFoundation +0x33964  _CFRunLoopRunSpecific
17 GraphicsServices +0x34dc _GSEventRunModal
18 UIKitCore +0x22aed8      -[UIApplication _run]
19 UIKitCore +0x22a514      _UIApplicationMain
20 SwiftUI +0x103385c       0x18d03f85c (0x18d03f7b8 + 164)
21 SwiftUI +0x10336a4       0x18d03f6a4 (0x18d03f610 + 148)
22 SwiftUI +0xc4f9f8        0x18cc5b9f8 (0x18cc5b978 + 128)
23 Twine +0x85a0            static iOSApp.$main() (iOSApp.swift)
24 dyld +0x5d80             start
msasikanth commented 5 months ago

The stack trace I posted in the issue description is from the XCode stack trace on the debug build.

KevinnZou commented 5 months ago

@msasikanth It should be fixed in 1.9.7. Please let me know if you encounter any further issues. Thanks again!

msasikanth commented 5 months ago

It's resolved now. Thanks šŸ™šŸ¾