KevinnZou / compose-webview-multiplatform

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

Add ability to enable dom storage in WebSettings #16

Closed LaatonWalaBhoot closed 7 months ago

LaatonWalaBhoot commented 7 months ago

`class WebSettings { var isJavaScriptEnabled = true

var customUserAgentString: String? = null

/**
 * Android platform specific settings
 */
val androidWebSettings = PlatformWebSettings.AndroidWebSettings()

/**
 * Desktop platform specific settings
 */
val desktopWebSettings = PlatformWebSettings.DesktopWebSettings()

/**
 * iOS platform specific settings
 */
val iOSWebSettings = PlatformWebSettings.IOSWebSettings

} `

As you can see there is no support to enable dom storage Which causes some web pages to turn blank. Example url : https://economictimes.indiatimes.com/tech/technology/amazon-launches-first-test-satellites-for-internet-network/articleshow/104223101.cms

KevinnZou commented 7 months ago

Thank you for your suggestion! There are a few methods to enable dom storage. For Android, there is a setting option available. However, even with dom storage enabled, I tested the provided URL but it still failed. I was also unable to open the URL in the browser. Is it possible for you to provide a different URL that I can test?

LaatonWalaBhoot commented 7 months ago

Android does expose a boolean to enable dom storage One aspect that I forgot to mention was that the webpage would load initially for a few milliseconds and then turn blank. I had seen the same behavior with the native Android webview and enabling dom storage had fixed it.

https://techcrunch.com/2023/10/06/brave-lays-off-9-of-its-workforce/ The above URL opens fine for example

https://medial.app/terms https://medial.app/privacy-policy Both these URLs show 500 with the message: Cannot read properties of undefined (reading getColorScheme) Adding a screenshot for reference

sc

I would also point out this only happens when running Android build iOS build opens all URLs perfectly. Please let me know if you need anything else. Happy to contribute. Great work on the library!

KevinnZou commented 7 months ago

I really appreciate your help! The new URLs work well and it is true that they fail on the Android side without enabling the dom storage. They also fail on the Desktop side. To solve that problem

For Android, I will add the option in the WebSettings so that developers can decide whether they need to use the local storage.

For the Desktop, it already supports the dom storage but needs some configuration. You just need to specify the cachePath in the init process of CEF. An example would be this:

Cef.init(builder = {
    installDir = File("jcef-bundle")
    settings {
        cachePath = File("cache").absolutePath
    }
}

For iOS, you need to do nothing because it enables local storage by default so all URLs will work perfectly.

Thank you for your help once again! Feel free to submit a PR directly if you have any future suggestions.

LaatonWalaBhoot commented 7 months ago

Really appreciate it. Have little to absolutely no idea about Desktop variations I think you have already raised a PR for both. Wanted to discuss this before moving ahead with a PR. Any idea when this will be merged and new version be released?

KevinnZou commented 7 months ago

Hi, I will merge it and release the new version today. Thanks again for your suggestions!

KevinnZou commented 7 months ago

1.4.0 has been released! https://github.com/KevinnZou/compose-webview-multiplatform/releases/tag/1.4.0

LaatonWalaBhoot commented 7 months ago

Thanks a lot. Really really appreciate it.