Hi there! I'm running into some issues when trying to set a payload on a hidden anchor element and downloading it by triggering the "click" method like the snippet below. Even though I haven't set any "onclick" closure myself on the hidden anchor element, I'm still running into Uncaught Error: closure invoked recursively or after being dropped
use wasm_bindgen::JsValue;
use web_sys::HtmlElement;
pub fn save_json(el: &HtmlElement, filename: &str, content: &str) -> Result<(), JsValue> {
let data = format!("data:text/json;charset=utf-8,{}", content);
el.set_attribute("href", data.as_str())?;
el.set_attribute("download", format!("{}.json", filename).as_str())?;
el.click(); // <-- the offending line. It simulates a click such that the browser downloads the file (when a completely different button is clicked, actually)
el.remove_attribute("href")?;
el.remove_attribute("download")?;
Ok(())
}
Any ideas on how to safely trigger an event method on an HtmlElement?