Open
Description
Describe the bug
In the documentation, it says it runs on all top-level document and child frame page navigations
but I think I misunderstood the following because when adding a way to tweak window
and navigator
properties to my internal plugin, it seemed like it only applied to the top
window and none of the iframes' window.
Reproduction
SETUP
- Navigate to a page that has a
data:
URL. - Scripts in this page creates an iframe to an external
https:
domain which contains an HTML document that is loaded.
PLUGIN
As simple as...
pub const INIT_SCRIPT: &str = r#"
console.log(-1, "Hello, from", window.location.origin);
const SCREEN_WIDTH = 393;
const SCREEN_HEIGHT = 852;
const tweak_screen = (prop, val) => window.screen.__defineGetter__(prop, () => val);
tweak_screen("height", SCREEN_HEIGHT);
tweak_screen("width", SCREEN_WIDTH);
tweak_screen("availHeight", SCREEN_HEIGHT);
tweak_screen("availWidth", SCREEN_WIDTH);
tweak_screen("pixelDepth", 24);
tweak_screen("colorDepth", 24);
window.__defineGetter__("innerHeight", () => SCREEN_HEIGHT);
window.__defineGetter__("innerWidth", () => SCREEN_WIDTH);
window.screen.orientation.__defineGetter__("type", () => "portrait-primary");
navigator.__defineGetter__("platform", () => "iPhone");
"#;
// ... in the plugin's `init` function ...
Builder::new("internal-api")
.js_init_script(INIT_SCRIPT.to_string())
.build()
DEMO
We can simply observe this by looking at the console and see that only a null
domain is logged while another log is expected from iframe.
Also, we can check if properties are modified in the iframe.
As we can see, they're only modified in the top
window but not in the iframe's window.
Expected behavior
Initialization script should also run in the iframe, as mentioned in the documentation.
Full tauri info
output
[✔] Environment
- OS: Mac OS 15.5.0 arm64 (X64)
✔ Xcode Command Line Tools: installed
✔ rustc: 1.87.0 (17067e9ac 2025-05-09)
✔ cargo: 1.87.0 (99624be96 2025-05-06)
✔ rustup: 1.28.2 (e4f3ad6f8 2025-04-28)
✔ Rust toolchain: stable-aarch64-apple-darwin (default)
- node: 24.1.0
- pnpm: 10.11.0
- yarn: 1.22.22
- npm: 11.4.1
- bun: 1.2.15
[-] Packages
- tauri 🦀: 2.5.1
- tauri-build 🦀: 2.2.0
- wry 🦀: 0.51.2
- tao 🦀: 0.33.0
- @tauri-apps/api : 2.5.0
- @tauri-apps/cli : 2.5.0
[-] Plugins
- tauri-plugin-opener 🦀: 2.2.6, (outdated, latest: 2.2.7)
- @tauri-apps/plugin-opener : 2.2.6 (outdated, latest: 2.2.7)
- tauri-plugin-http 🦀: 2.4.3, (outdated, latest: 2.4.4)
- @tauri-apps/plugin-http : 2.4.3 (outdated, latest: 2.4.4)
- tauri-plugin-dialog 🦀: 2.2.1, (outdated, latest: 2.2.2)
- @tauri-apps/plugin-dialog : 2.2.1 (outdated, latest: 2.2.2)
- tauri-plugin-os 🦀: 2.2.1
- @tauri-apps/plugin-os : 2.2.1
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist
- devUrl: http://localhost:1420/
- framework: SolidJS
- bundler: Vite
[-] iOS
- Developer Teams: Mikkel ALMONTE--RINGAUD (ID: WLAPHT4WXV)
Stack trace
Additional context
No response