Skip to content

Add the support of offscreen canvas - #8554

Open
Alex-PLACET wants to merge 3 commits into
emilk:mainfrom
Alex-PLACET:offscreen_canva
Open

Add the support of offscreen canvas#8554
Alex-PLACET wants to merge 3 commits into
emilk:mainfrom
Alex-PLACET:offscreen_canva

Conversation

@Alex-PLACET

@Alex-PLACET Alex-PLACET commented Sep 11, 2026

Copy link
Copy Markdown

Hello,

This is a pull request to add the support of OffscreenCanvas

The context and my goal is to be able to run rerun (or any other library/sdk with egui GUI) into JupyterLite.

This adds a way to run an eframe app on an OffscreenCanvas owned by a Web Worker, instead of the <canvas> element in the page. The classic main-thread path is untouched: nothing changes unless you use the new entry point.

WebCanvas (crates/eframe/src/web/canvas.rs) is a small Html / Offscreen enum that the runner, the event wiring and both painters (glow and wgpu) now go through. The offscreen kind is what the new OffscreenCanvas / OffscreenCanvasRenderingContext2d web-sys features are for.

A worker has no DOM, and DOM events can't be constructed or structured-cloned into it, so the host page keeps the listeners and forwards raw pointer/wheel/modifier data as plain messages (web/host.rs on the Rust side). The worker parses those back into egui events (web_events.rs), and from there it is the same input pipeline as always.

Glyph/font loading and web_location() used to need window/document, they now fall back gracefully inside a worker, which is what lets the demo render there with its icons intact. WebInfo::offscreen_canvas tells the app which mode it is running in, and the demo's Backend panel shows it.

image

There is a demo page dedicated for offscreencanvas: web_demo/offscreen.html. To try it:

./scripts/build_demo_web.sh --glow
cd web_demo && python3 -m http.server 8765
# then open http://127.0.0.1:8765/offscreen.html

@github-actions

Copy link
Copy Markdown

Preview is being built...

Preview will be available at https://egui-pr-preview.github.io/pr/8554-offscreen_canva

View snapshot changes at kitdiff

@Alex-PLACET
Alex-PLACET marked this pull request as ready for review September 11, 2026 08:55
@Wumpf
Wumpf requested review from Wumpf and lucasmerlin September 11, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant