Skip to content

Confused about web_sys + clipboard usage #3223

Answered by miketwenty1
miketwenty1 asked this question in Q&A
Discussion options

You must be logged in to vote

I solved my issue:

use wasm_bindgen_futures::spawn_local;
let _task = spawn_local(async move {
    let window = web_sys::window().expect("window"); // { obj: val };
    let nav = window.navigator().clipboard();
    match nav {
        Some(a) => {
            let p = a.write_text("please god work");
            let result = wasm_bindgen_futures::JsFuture::from(p)
                .await
                .expect("clipboard populated");
            info!("clippyboy worked");
        }
        None => {
            warn!("failed to copy clippyboy");
        }
    };
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Liamolucko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant