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

setCookie didn't work #105

Closed vivaCoda54 closed 3 months ago

vivaCoda54 commented 3 months ago

Hello, I add two cookie for my webview state.cookieManager.setCookie( domain, Cookie( name = "token", value = cookieString, domain = domain, path = "/", ) ) state.cookieManager.setCookie( domain, Cookie( name = "appSource", value = "mobileApp", domain = domain, path = "/", ) )

            but when I get the number ok cookies before to add them, I have 15, and after to add them I have also 15. It seems that the add didn't work. Could you help me?
            Thanks you
KevinnZou commented 3 months ago

@vivaCoda54 Can you please provide the complete code for setting a cookie? You could also refer to this sample for reference.

vivaCoda54 commented 3 months ago

@KevinnZou with your sample, now the setCookie works. But the issue is that I need this cookie to be send before the page is load in the webview. So in my log I have the webview loaded, and then the setCookie. When I try to wait for the cookie to be set before to load the webview, the webview didn't showing. So I tried to reload the page when the cookie is set, but my page didn't take account of the modifications. I need my wordpress page to have a cookie to detekt if the page is loaded from a mobileApp and then adjust some UI. It works well with AndroidView and Webview, but I use your plugin for iOS and it didn't works. SO I also have the header and footer of my page visibles.

KevinnZou commented 3 months ago

@vivaCoda54 Thanks for your explanation! I understand your need now. Did you try to use disposableEffect to set the cookie before the Webview loading? However, I am not quite sure whether that will work since iOS may not support doing that.

One solution I would suggest is to use a header instead of a cookie to tag the mobile app. This should work during the initial loading.

vivaCoda54 commented 3 months ago

@KevinnZou I will try the DisposableEffect. I already try to use headers, it works, but the issue is that I need to send wordpress_logged_in cookie to show that user is connected on a wordpress page, so only cookies work for that...

vivaCoda54 commented 3 months ago

@KevinnZou Finally I just use the sample and proceed with the number of cookies before and after set. I the number it's not the same, I reload the webview. It work like that for the wordpress logged_in cookie