KevinnZou / compose-webview-multiplatform

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

Some websites fail to load - getColorScheme error #103

Closed LaatonWalaBhoot closed 3 months ago

LaatonWalaBhoot commented 3 months ago

In android devices certain urls give

[INFO:CONSOLE(5)] "Uncaught TypeError: Cannot read properties of null (reading 'getItem')", source: https://medial.app/privacy-policy (5) [INFO:CONSOLE(1)] "TypeError: Cannot read properties of undefined (reading 'getColorScheme')", source: https://medial.app/_nuxt/entry.4795caa5.js (1) [INFO:CONSOLE(1)] "[nuxt] error caught during app initialization Error: Cannot read properties of undefined (reading 'getColorScheme')", source: https://medial.app/_nuxt/entry.4795caa5.js (1)

webview version: 1.8.8 tested urls: medial.app/privacy, medial.app/terms-of-service

Tested in web chrome browser and they work fine. I have enabled dom storage, but still getting this error

KevinnZou commented 3 months ago

@LaatonWalaBhoot Thanks for your feedback! I also reproduce the error. After conducting some tests, I have identified that the problem is caused by a delay in applying the web settings. We are currently using LaunchedEffect to initialize the web settings, but it seems to be delayed until the WebView is initialized. As a result, our custom settings are not being applied to the WebView at all.

To solve it, we can simply use DisposableEffect to init the WebSetting like that:

DisposableEffect(Unit) {
        state.webSettings.apply {
            androidWebSettings.domStorageEnabled = true
            desktopWebSettings.disablePopupWindows = true
            allowFileAccessFromFileURLs = true
            logSeverity = KLogSeverity.Debug
            customUserAgentString =
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1) AppleWebKit/625.20 (KHTML, like Gecko) Version/14.3.43 Safari/625.20"
        }

        onDispose {  }
    }

I apologize for any inconvenience caused by this issue. If you have any further questions, please let me know.

LaatonWalaBhoot commented 3 months ago

@KevinnZou Thanks. Now it makes sense. My loading bar is immediately displayed as well. Maybe add this to the documentation? You can go ahead and close this issue. It is resolved for me.

PS: No need to apologize. Kudos to you for this amazing library.

KevinnZou commented 3 months ago

@LaatonWalaBhoot Sure, I will update the documentation and example later. Thanks for your feedback again!