Skip to content

Native web view element (for inline players such as YouTube embeds) #412

Open

Description

@square3ang

What

An element that hosts a native web view (WebView2 on Windows, WKWebView on macOS, WebKitGTK on Linux) inside a Rune window, laid out like any other El: it takes the element's bounds, clips with its ancestors' scroll viewports, and hides when the element unmounts.

Why

A chat client (Reflux, a Fluxer client on Rune) shows YouTube link embeds. The web client plays them inline by swapping the poster for the YouTube <iframe> player. A Rune app can't do that today: the only options are opening the browser, or resolving a direct stream (yt-dlp) for the GStreamer player, which isn't YouTube's player and depends on an external tool.

Why an app can't do it alone

  • Rune doesn't hand out the app window's native handle, so a crate like wry has nothing to attach a child web view to.
  • On Linux, wry's build_as_child works on X11 only; on Wayland a web view must be a GTK widget or its own subsurface, which needs the window's wl_surface and Rune's cooperation (a subsurface placed and synchronised with Rune's frames).
  • A separate web-view window (own process, tao loop) works, but it isn't inline and doesn't move or scroll with the message.

Sketch

  • El::web_view(url) (or a WebView handle with load_url, eval, on_navigate), positioned by layout each frame.
  • Wayland: a wl_subsurface under the Rune surface for WebKitGTK (or WPE), committed in sync with Rune's frame.
  • X11 / Windows / macOS: a native child window/view at the element's rect.
  • Behaviour while overlapped: native views draw above the canvas, so popups/menus over them need either clipping the view or hiding it while an overlay covers it.

Minimum useful: a fixed-size inline view inside a scrolling list that follows scroll and clips to the viewport.

Activity

  1. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up and the platform breakdown.

    One correction on "Rune doesn't hand out the app window's native handle": it does now. WindowHandle::with_raw_handle (crates/rune/src/window/handle.rs) lends out winit's raw window handle, and App::on_window runs each time the native window is created, so that's the place to attach a child view. On current dev there's also WindowHandle::with_raw_display_handle (the wl_display on Wayland) and App::on_display_close for cleaning up foreign objects before the display closes. #1680 shows a WKWebView embedded this way with wry's build_as_child on macOS. It also notes that VoiceOver can't reach a child view added like that.

    That lets you attach a fixed native view by hand on Windows, macOS and X11. It doesn't cover what you're asking for, and I didn't find any of it in the code:

    • an El whose native view follows layout, follows scroll and clips to its scroll ancestors;
    • hiding the view on unmount or while an overlay covers it;
    • on Wayland, a wl_subsurface committed in step with Rune's frames.

    Your minimum (a fixed-size inline view in a scrolling list that follows scroll and clips to the viewport) is a good first target, and I'm keeping this open as a feature request on that basis.

  2. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    I haven't opened a PR for this. A real web view element needs a native backend per platform (WebView2, WKWebView, WebKitGTK on X11, and a wl_subsurface synced with Rune's frames on Wayland). It also needs new runtime work: clipping the view to its scroll ancestors, and hiding it on unmount or under an overlay. That's too much to write and check here without seeing it run on each platform, and where it lives, its dependencies and how overlays work with it are maintainer decisions.

    Until then, on Windows, macOS and X11 you can place a child web view (for example wry's build_as_child) yourself with what's already in Rune:

    • Attach: App::on_window runs each time the native window is created; call WindowHandle::with_raw_handle from it to get the parent handle.
    • Follow scroll: El::on_drawn_layout_tx (call tx.live_only() in it) or El::drawn_rect_into on the embed's placeholder reports where each frame draws it, in window points, including during a scroll. Multiply by Tx::scale to get pixels for set_bounds.
    • Hide: El::on_visible tells you when the placeholder goes on or off screen, and you can hide the view when the row unmounts.

    What this can't do yet: the reported rect is the element's whole drawn rect, not the part left after the scroll viewport clips it. So a view half scrolled out of the list sticks out past the list's edge rather than being cut off. Wayland also still has no way to do it. Those two gaps are where Rune would need to change. Also see #1680: a child view attached this way isn't reachable by VoiceOver on macOS.

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