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.
// 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, _| {
// Delay 10 ms, and focus again.
let func = js_sys::Function::new_no_args(&format!(
"document.getElementById('{AGENT_ID}').focus()"
));
window
.set_timeout_with_callback_and_timeout_and_arguments_0(&func, 10)
.unwrap();
let input_refocus = input_refocus.clone();
call_after_delay(std::time::Duration::from_millis(10), move || {
input_refocus.focus().ok();
});
})?;
body.append_child(&input)?;

View File

@ -167,7 +167,7 @@ impl eframe::App for ImageViewer {
if !matches!(self.fit, ImageFit::Original { .. }) {
self.fit = ImageFit::Original { scale: 1.0 };
}
let ImageFit::Original{scale} = &mut self.fit else {
let ImageFit::Original { scale } = &mut self.fit else {
unreachable!()
};
ui.add(Slider::new(scale, 0.1..=4.0).text("scale"));