Closed martpie closed 6 months ago
It would seem the URL is not actually empty, but definitely wrong, here's a debug of window.url()
[2024-03-31][14:54:33][INFO][...] Url {
scheme: "about",
cannot_be_a_base: true,
username: "",
password: None,
host: None,
port: None,
path: "blank",
query: None,
fragment: None,
}
For people looking for a workaround, I ended up using on_page_load
instead
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::<R>::new("default-view")
.invoke_handler(tauri::generate_handler![set])
.on_page_load(|webview, payload| {
if webview.label().eq("main") && payload.event() == PageLoadEvent::Finished {
let config_manager = webview.state::<ConfigManager>();
let mut url = payload.url().clone();
let default_view = config_manager.get().default_view;
let fragment = match default_view {
DefaultView::Library => "/library",
DefaultView::Playlists => "/playlists",
};
info!("Navigating to '{}'", fragment);
url.set_fragment(Some(fragment));
// For some reasons, it does not seem possible to navigate directly
// from the webview argument, as we cannot make it &mut
webview
.app_handle()
.get_webview_window("main")
.unwrap()
.navigate(url)
}
})
.build()
}
Yup, on_webview_ready simply triggers too early. It triggers when the webview was started/registered, not when it navigated to the app's "website". Afaik webview2 has no config for an actual init page so it always starts on about:blank before we can navigate to the actual url.
Maybe it makes sense to remove on_webview_ready in its current state completely and also use navigation based hooks like we do outside of plugins (on the app and windows)...
Describe the bug
I have a small plugin that navigates to a certain URL hash based on some configuration saved by the user, the plugin roughly look like the following:
on macOS, the correct view gets loaded. On Windows, a blank page is displayed when starting the app (I did not test on Linux).
window.location = "http://localhost:1420"
from the webview console loads the app correctlyDigging a bit, and logging the
url
variable, it appears empty:So when I mutate it, it of course loads nothing.
Reproduction
cf. code above.
Expected behavior
No response
Full
tauri info
output