Skip to content

Commit

Permalink
Prevent panic when copying text outside of a secure context
Browse files Browse the repository at this point in the history
  • Loading branch information
YgorSouza committed Oct 30, 2024
1 parent dafcfda commit 21d961a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/eframe/src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ fn set_cursor_icon(cursor: egui::CursorIcon) -> Option<()> {
/// Set the clipboard text.
fn set_clipboard_text(s: &str) {
if let Some(window) = web_sys::window() {
if !window.is_secure_context() {
log::error!(
"Clipboard is not available because we are not in a secure context. \
See https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
);
return;
}
let promise = window.navigator().clipboard().write_text(s);
let future = wasm_bindgen_futures::JsFuture::from(promise);
let future = async move {
Expand Down

0 comments on commit 21d961a

Please sign in to comment.