Skip to content

Commit

Permalink
Fix browser creation callback not being called for edge2 if the conte…
Browse files Browse the repository at this point in the history
…nt couldn't load.
  • Loading branch information
bamidev committed Mar 3, 2024
1 parent cdca4bd commit f8918d8
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/core/browser_window/edge2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,16 @@ impl BrowserWindowExt for BrowserWindowImpl {
.expect("unable to get web message as json");

let handle = BrowserWindowImpl { inner: bw_inner };
if string == "\"__bw_loaded\"" {
// Once the `ìnvoke_extern` function exists, invoke the creation
// callback.
creation_callback(handle, callback_data);
} else {
match JsValue::from_json(&string) {
JsValue::Array(args) => {
let command = args[0].to_string_unenclosed();
let command_args = args[1..].to_vec();
handler(handle, &command, command_args);
}
_ => panic!(
"unexpected JavaScript value received from Edge WebView2"
),
match JsValue::from_json(&string) {
JsValue::Array(args) => {
let command = args[0].to_string_unenclosed();
let command_args = args[1..].to_vec();
handler(handle, &command, command_args);
}
_ => panic!(
"unexpected JavaScript value received from Edge WebView2"
),
}

Ok(())
})
.expect("unable to register message handler");
Expand All @@ -175,17 +168,15 @@ impl BrowserWindowExt for BrowserWindowImpl {
function invoke_extern(...args) {
window.chrome.webview.postMessage([].slice.call(args));
}
addEventListener("DOMContentLoaded", (e) => {
window.chrome.webview.postMessage("__bw_loaded");
});
"#,
move |_| Ok(()),
);

// TODO: Register the DOM content-loaded event.
// At the moment, we're using a workaround by sending a message from JS because
// the webview2 crate doesn't wrap it (yet).
webview.add_navigation_completed(move |wv, e| {
let handle = BrowserWindowImpl { inner: bw_inner };
creation_callback(handle, callback_data);
Ok(())
});

Ok(())
});
Expand Down

0 comments on commit f8918d8

Please sign in to comment.