emilk / emilk/egui

`request_repaint` panics when used from a Web Worker

Open
#4,368 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug eframe web
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

**Describe the bug**

Using `request_repaint` (or any of its variants) from a Web Worker panics. The panic info points here:

https://github.com/emilk/egui/blob/a8501c963dba0f14a8feff28ed91ff245956662c/crates/eframe/src/web/mod.rs#L60-L67

It seems like eframe ends up trying to get the time, but the `now_sec` function uses the JS Window object which isn't available from a Web Worker.

Right now, my workaround is to force my app to run at 60fps continuous during the loading time, instead of repainting when needed.

**Screenshots**

![image](https://github.com/emilk/egui/assets/4533568/1e16d708-dc89-495d-899a-d879f76ba62a)

**Desktop (please complete the following information):**
- Chrome 123, Firefox 124

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at crates/eframe/src/web/mod.rs around lines 60-67 and inspect the now_sec function referenced in the report. Reproduce request_repaint from a Web Worker in Chrome or Firefox, then verify that the repaint request no longer panics when the worker lacks a JS Window object.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.