I try to create a webview manually redirecting to an external URL giving an initialization script.
use include_flate::flate;
use tauri::{App, WebviewUrl, WebviewWindowBuilder};
use url::Url;
flate!(pub static INJECTION: str from "./dist/index.js");
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let app_url = Url::parse("https://ecole-directe.plus/login").unwrap();
let app_url_external = WebviewUrl::External(app_url);
let injection = INJECTION.clone();
tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.invoke_handler(tauri::generate_handler![])
.setup(move |app: &mut App| {
let win = WebviewWindowBuilder::new(app, "main", app_url_external)
.title("Ecole Directe Plus")
.resizable(true)
.disable_drag_drop_handler()
.decorations(true)
.shadow(true)
.inner_size(1280.0, 720.0)
.initialization_script(injection)
.build()?;
win.open_devtools();
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
I allowed the remote URL as mentionend in the documentation in my capabilities :
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"remote": {
"urls": ["https://ecole-directe.plus/*"]
},
"windows": ["main"],
"permissions": [
"core:path:default",
"core:event:default",
"core:window:default",
"core:app:default",
"core:resources:default",
"core:menu:default",
"core:tray:default",
"core:window:allow-set-fullscreen",
"core:window:allow-start-dragging",
"core:webview:default",
"core:webview:allow-set-webview-zoom",
{
"identifier": "http:default",
"allow": [
{
"url": "https://**/*"
},
{
"url": "http://**/*"
}
]
}
]
}
But sadly, when I run the app, I get the following errors in the terminal :
[Warning] [blocked] The page at https://ecole-directe.plus/login requested insecure content from ipc://localhost/plugin%3Aevent%7Cemit. This content was blocked and must (user-script:3, line 83)
[Error] Not allowed to request resource
sendIpcMessage (user-script:3:83)
(anonymous function) (user-script:5:177)
action (user-script:5:311)
(anonymous function) (user-script:5:320)
Promise
value (user-script:5:300)
h (user-script:9:1:1964)
(anonymous function) (user-script:9:1:6641)
L (user-script:9:1:6683)
(anonymous function) (user-script:11:26)
(anonymous function) (user-script:11:16)
Global Code (user-script:11:49)
[Error] Fetch API cannot load ipc://localhost/plugin%3Aevent%7Cemit due to access control checks.
sendIpcMessage (user-script:3:83)
(anonymous function) (user-script:5:177)
action (user-script:5:311)
(anonymous function) (user-script:5:320)
Promise
value (user-script:5:300)
h (user-script:9:1:1964)
(anonymous function) (user-script:9:1:6641)
L (user-script:9:1:6683)
(anonymous function) (user-script:11:26)
(anonymous function) (user-script:11:16)
Global Code (user-script:11:49)
and the page won't load anymore, nothing works, not even the console !