emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.53k stars 1.61k forks source link

Clipboard access on non https site breaks app #5388

Closed e00E closed 5 days ago

e00E commented 6 days ago

This issue is out of egui's control. I'm creating it to help other people running into it when they search for the error message.

Description

When you try to use the clipboard in egui web app for example by selecting text and pressing ctrl-c to copy it, then you get an error in the console and the whole app freezes forever. This only happens if you access the site over http instead of https. On localhost like through trunk serve it does not happen either.

In Firefox the error starts with this line:

Uncaught TypeError: getObject(...) is undefined

In Chrome the error starts with this line:

Uncaught TypeError: Cannot read properties of undefined (reading 'writeText')

Explanation

Egui since version.0.29.0 supports clipboard access on the web. In egui code this happens through window.navigator().clipboard(). As the MDN page warns:

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

This is not reflected in this web-sys API, which causes a panic when the API is not available like in this case. The issue has been reported here https://github.com/rustwasm/wasm-bindgen/issues/4085 .

lucasmerlin commented 5 days ago

There already is https://github.com/emilk/egui/issues/5293 and a PR https://github.com/emilk/egui/pull/5326 for this, so I'm closing this as a duplicate. This should be "fixed" in the next egui release (we will log a helpful error message and added a note to the docs).