Skip to content

WryCookieManager.getCookies always throw WrongThread exception on Windows. #25

Closed

Description

@Tlaster

Remove withContext(Dispatchers.IO) from here can resolve the issue. I've tested on my Windows PC.
A workaround is to use WebViewState.nativeWebView.getCookiesForUrl

Activity

  1. kdroidFilter commented on Feb 26, 2026

    @kdroidFilter
    Collaborator

    Does #26 fix this?

  2. Tlaster commented on Feb 26, 2026

    @Tlaster
    ContributorAuthor

    Does #26 fix this?

    No, #26 is a different feature request.

  3. KRTirtho commented on Apr 30, 2026

    @KRTirtho
    Contributor

    It requires EDT. So I modified the getCookies to use SwingUtilities.invokeAndWait and it seems to fix the problem on Windows and the demo application actually is successfully get the cookies instead of just returning an emptyList

    class WryWebViewPanel(...){
    // ... other stuff
         fun getCookiesForUrl(url: String): List<WebViewCookie> {
            var result: List<WebViewCookie> = emptyList()
            val id = webviewId ?: run {
                log("getCookiesForUrl webviewId is null")
                return result
            }
    
            val action = {
                result = runCatching { NativeBindings.getCookiesForUrl(id, url) }
                    .onFailure { log("getCookiesForUrl failed: ${it.message}"); it.printStackTrace() }
                    .getOrDefault(emptyList())
            }
    
            if (SwingUtilities.isEventDispatchThread()) action() else SwingUtilities.invokeAndWait(
                action
            )
            return result
        }
    
        fun getCookies(): List<WebViewCookie> {
            var result: List<WebViewCookie> = emptyList()
            val id = webviewId ?: run {
                log("getCookies webviewId is null")
                return result
            }
    
            val action = {
                result = runCatching { NativeBindings.getCookies(id) }
                    .onFailure { log("getCookies failed: ${it.message}"); it.printStackTrace() }
                    .getOrDefault(emptyList())
            }
    
            if (SwingUtilities.isEventDispatchThread()) action() else SwingUtilities.invokeAndWait(
                action
            )
            return result
        }
    // ... other stuff
    }
  4. KRTirtho commented on Apr 30, 2026

    @KRTirtho
    Contributor

    I'll create a PR with the fix soon once I confirm other platforms are also working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions