Skip to content

Expose WebView navigation interception (with URL + cancel) and cookie access API in v3 #5799

Description

@wsczx

Wails version family

v3

Operating System

Windows

Description

In Wails v3 (v3.0.0-alpha2.117), the WebView is the only way to render a third-party login / SAML / SSO page inside the app. A common auth flow is: open an external auth URL in the WebView → the provider finishes login and redirects to a callback URL that carries a token (e.g. .../callback?token=... or http://localhost:PORT/callback?token=...) → the app must capture that token and close the WebView.

Currently there is no supported way to capture a token delivered via a redirect URL or a cookie from inside the WebView. This blocks two real scenarios:

  • Mobile (iOS/Android): the app sandbox forbids binding a localhost port, so a localhost callback listener is impossible. The token must be captured from within the WebView.
  • Desktop: without navigation/cookie access, the only fallback is running a localhost listener, which we want to avoid.

To Reproduce

  1. Create a Wails v3 app with a WebView.
  2. Load an external URL that, after some interaction, redirects to a custom callback URL containing a token (e.g. myapp://callback?token=abc).
  3. Try to detect that navigation from Go/TS to extract the token and stop the navigation.
  4. Observe that no public API provides the target URL during navigation, and the only navigation event (WebViewNavigationCompleted) does not include the URL.
  5. Alternatively, try to read the WebView's cookies after auth completes — no public cookie API exists.

Expected behaviour

  • A navigation hook that exposes the target URL and allows cancelling the navigation, e.g.
webview.OnNavigationStarting(func(url string) bool {
    if strings.HasPrefix(url, "myapp://callback") {
        token := extract(url)
        return false // cancel
    }
    return true
})
  • A cookie access API, e.g. webview.GetCookies() / webview.SetCookie(...).

Screenshots

No response

Attempted Fixes

  • Used the internal navigationStarting handler — it exists but is not exposed to Go/TS with the URL and cannot cancel navigation.
  • Used the public WebViewNavigationCompleted event — it fires but does not include the URL.
  • Worked around it on desktop by running a localhost callback listener to catch the redirect — works on desktop but is impossible on mobile (sandbox forbids port binding).

System Details

- Wails v3: v3.0.0-alpha2.117
- Go: (fill your version, e.g. go1.22.x)
- OS / Platform: macOS / Windows / Linux (desktop) + iOS / Android (mobile)
- Frontend: (e.g. vanilla JS / React / etc.)

Additional context

This is required for SSO / SAML / OAuth flows where the token is delivered via a post-login redirect or a session cookie. On mobile especially, a localhost listener is not an option, so in-WebView capture (navigation interception or cookie read) is the only viable path. A minimal, unified API across desktop and mobile would let the same auth code run everywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions