Add the support of offscreen canvas - #8554
Open
Alex-PLACET wants to merge 3 commits into
Open
Conversation
|
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
marked this pull request as ready for review
September 11, 2026 08:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
OffscreenCanvasowned 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 smallHtml/Offscreenenum that the runner, the event wiring and both painters (glow and wgpu) now go through. The offscreen kind is what the newOffscreenCanvas/OffscreenCanvasRenderingContext2dweb-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.rson 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 needwindow/document, they now fall back gracefully inside a worker, which is what lets the demo render there with its icons intact.WebInfo::offscreen_canvastells the app which mode it is running in, and the demo's Backend panel shows it.There is a demo page dedicated for offscreencanvas:
web_demo/offscreen.html. To try it: