You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Web: display cross-origin raster images without pixel access #1667
ImageCache::url cannot display a cross-origin raster image when the image server omits CORS, even though Chromium can display the same URL in an ordinary <img>. The web loader uses fetch, then reads the decoded pixels.
Repro: Serve a PNG from a second localhost origin, with no Access-Control-Allow-Origin. On the page, img.src = url; await img.decode() succeeds; ImageCache::url(url, 32.0, 1.0) reports an error. In headless Chromium, the pinned Rune web loader rejected the URL while <img> decoded it at 8×4; adding Access-Control-Allow-Origin: * made both paths succeed.
Could Rune expose an opt-in, display-only web image element that participates in layout and clipping without reading pixels? The browser should keep its normal cross-origin restrictions; this mode would not expose bitmap bytes or bypass CORS.
Thanks for the clear repro. You're right that this is a limitation: Rune's web loader (crates/rune-image/src/from_url.js) fetches the bytes, decodes them with createImageBitmap and reads the pixels back through a canvas so Rune can draw them on the GPU. A cross-origin response without CORS can't go through that path. WEB.md and the ImageCache::url docs say such images resolve to Image::error, so it works as documented today, and I'm treating this as a feature request.
As I understand the proposal, it's an opt-in, web-only image view backed by a real <img> element:
it takes part in Rune's layout (it has a size and position like any view);
the <img> is positioned over the canvas and clipped with CSS to the view's clip rect and corner radius;
Rune never reads its pixels, so the browser's normal cross-origin rules stay in place.
One limit to keep in mind: a DOM element can only sit above or below the whole canvas. It can't be layered between things Rune draws, and some effects (blur, shaders, opacity groups that span canvas content) won't apply to it. So it fits places like avatars and thumbnails better than images under overlays. Clipping, borders and rounded corners can be matched with CSS.
I looked into building this and stopped before writing code. It needs a few design decisions first, and I don't want to guess at them.
On web, Rune draws every image as pixels on the GPU (crates/rune-image/src/from_url.js). The only DOM it keeps over the canvas is the hidden accessibility mirror (crates/rune/src/runtime/web/a11y.rs), and that only rebuilds when the app updates its views, about every 0.1 s while motion runs. A visible <img> would need:
A new element type that goes through layout but that the canvas renderers skip.
A DOM layer updated on every drawn frame, including scroll-only frames and animated transforms. Otherwise the image falls behind the content around it.
A stacking choice. Above the canvas, it covers Rune's popovers, menus and sheets. Below it, the canvas has to leave a transparent hole at that spot, which would also show through any translucent canvas drawing above it.
Clipping to every enclosing scroll view and rounded clip, not just its own rect.
Until this exists, the way to get these images through ImageCache::url is to serve them with Access-Control-Allow-Origin or proxy them through your own origin.
If you have a use case that settles the stacking question, for example images only inside scrolling lists and never under overlays, please add it here. It would narrow down what a first version needs to do.
Added opt-in El::web_image(url) and El::web_image_fit(url, fit) backed on web by a lazily mounted [data-rune-web-images] DOM <img> layer (sitting above canvas[data-rune-canvas] and directly before [data-rune-a11y], with pointer-events: none and aria-hidden="true").
The bridge never sets crossOrigin, never calls fetch/createImageBitmap/drawImage, and never reads bitmap pixels, so browsers enforce normal cross-origin restrictions while displaying images whose servers omit Access-Control-Allow-Origin.
Visible draws synchronize on every frame (including scroll, animation, zoom, and App::web_document), reusing <img> elements by stable NodeId without reassigning src, inset inside visible element borders, clipped by nested rectangular and rounded clip wrappers (El::clip_rounded / El::clip_corners), and supporting SurfaceFit, El::surface_anchor, El::surface_unscaled, El::image_filter(ImageFilter::Nearest), opacity, rotation, and --html static export.
Stacking trade-off: placing the layer above the canvas keeps WebGPU, WebGL2, and opaque CPU-first canvases working cleanly with El::fill / El::border underneath, at the cost that canvas-drawn popovers/overlays and shaders cannot composite over a web_image. Existing ImageCache::url + El::pixels is unchanged for same-origin or CORS-enabled images.
Verification:
Verified locally: Rust unit tests (cargo test -p rune --lib web_image, 7 passed; export::tests, 13 passed), wasm32-unknown-unknown WebGPU (cargo check-wasm) and WebGL2 (cargo check-webgl) builds, and Node DOM harness tests (node --test crates/rune/src/platform/web/bridge.test.mjs, 81 passed).
Not run locally: live Chromium/Firefox/Safari browser requests against a real cross-origin HTTP image server without CORS headers.
Please reopen if anything behaves unexpectedly in a real browser.
Activity
opencodejr commentedon Nov 25, 2026
Thanks for the clear repro. You're right that this is a limitation: Rune's web loader (
crates/rune-image/src/from_url.js)fetches the bytes, decodes them withcreateImageBitmapand reads the pixels back through a canvas so Rune can draw them on the GPU. A cross-origin response without CORS can't go through that path.WEB.mdand theImageCache::urldocs say such images resolve toImage::error, so it works as documented today, and I'm treating this as a feature request.As I understand the proposal, it's an opt-in, web-only image view backed by a real
<img>element:<img>is positioned over the canvas and clipped with CSS to the view's clip rect and corner radius;One limit to keep in mind: a DOM element can only sit above or below the whole canvas. It can't be layered between things Rune draws, and some effects (blur, shaders, opacity groups that span canvas content) won't apply to it. So it fits places like avatars and thumbnails better than images under overlays. Clipping, borders and rounded corners can be matched with CSS.
opencodejr commentedon Nov 25, 2026
I looked into building this and stopped before writing code. It needs a few design decisions first, and I don't want to guess at them.
On web, Rune draws every image as pixels on the GPU (
crates/rune-image/src/from_url.js). The only DOM it keeps over the canvas is the hidden accessibility mirror (crates/rune/src/runtime/web/a11y.rs), and that only rebuilds when the app updates its views, about every 0.1 s while motion runs. A visible<img>would need:Until this exists, the way to get these images through
ImageCache::urlis to serve them withAccess-Control-Allow-Originor proxy them through your own origin.If you have a use case that settles the stacking question, for example images only inside scrolling lists and never under overlays, please add it here. It would narrow down what a first version needs to do.
Hona commentedon Nov 27, 2026
Merged in #2637 (
d95e83aab).Design decision:
El::web_image(url)andEl::web_image_fit(url, fit)backed on web by a lazily mounted[data-rune-web-images]DOM<img>layer (sitting abovecanvas[data-rune-canvas]and directly before[data-rune-a11y], withpointer-events: noneandaria-hidden="true").crossOrigin, never callsfetch/createImageBitmap/drawImage, and never reads bitmap pixels, so browsers enforce normal cross-origin restrictions while displaying images whose servers omitAccess-Control-Allow-Origin.App::web_document), reusing<img>elements by stableNodeIdwithout reassigningsrc, inset inside visible element borders, clipped by nested rectangular and rounded clip wrappers (El::clip_rounded/El::clip_corners), and supportingSurfaceFit,El::surface_anchor,El::surface_unscaled,El::image_filter(ImageFilter::Nearest), opacity, rotation, and--htmlstatic export.El::fill/El::borderunderneath, at the cost that canvas-drawn popovers/overlays and shaders cannot composite over aweb_image. ExistingImageCache::url+El::pixelsis unchanged for same-origin or CORS-enabled images.Verification:
cargo test -p rune --lib web_image, 7 passed;export::tests, 13 passed),wasm32-unknown-unknownWebGPU (cargo check-wasm) and WebGL2 (cargo check-webgl) builds, and Node DOM harness tests (node --test crates/rune/src/platform/web/bridge.test.mjs, 81 passed).Please reopen if anything behaves unexpectedly in a real browser.