Remove Function() invocation from eframe text_agent to bypass "unsafe-eval" restrictions in Chrome browser extensions. (#3349)

* remove Function (eval) from eframe text agent for compatibility with browser extensions.

* cargo fmt on image viewer
This commit is contained in:
aspect 2023-09-17 14:25:50 +03:00 committed by GitHub
parent d949eaf682
commit 9c4f55b1f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -101,14 +101,13 @@ pub fn install_text_agent(runner_ref: &WebRunner) -> Result<(), JsValue> {
// When input lost focus, focus on it again. // When input lost focus, focus on it again.
// It is useful when user click somewhere outside canvas. // It is useful when user click somewhere outside canvas.
let input_refocus = input.clone();
runner_ref.add_event_listener(&input, "focusout", move |_event: web_sys::MouseEvent, _| { runner_ref.add_event_listener(&input, "focusout", move |_event: web_sys::MouseEvent, _| {
// Delay 10 ms, and focus again. // Delay 10 ms, and focus again.
let func = js_sys::Function::new_no_args(&format!( let input_refocus = input_refocus.clone();
"document.getElementById('{AGENT_ID}').focus()" call_after_delay(std::time::Duration::from_millis(10), move || {
)); input_refocus.focus().ok();
window });
.set_timeout_with_callback_and_timeout_and_arguments_0(&func, 10)
.unwrap();
})?; })?;
body.append_child(&input)?; body.append_child(&input)?;