Skip to content

Commit 022eed4

Browse files
authored
fix(core): nested isolation iframes, closes #4015 (#4020)
1 parent 8f259f4 commit 022eed4

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fixes nested isolation iframe injection.

core/tauri/scripts/isolation.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
// SPDX-License-Identifier: MIT
44

55
window.addEventListener('DOMContentLoaded', () => {
6-
let style = document.createElement('style')
7-
style.textContent = __TEMPLATE_style__
8-
document.head.append(style)
6+
if (window.location.origin.startsWith(__TEMPLATE_origin__)) {
7+
let style = document.createElement('style')
8+
style.textContent = __TEMPLATE_style__
9+
document.head.append(style)
910

10-
let iframe = document.createElement('iframe')
11-
iframe.id = '__tauri_isolation__'
12-
iframe.sandbox.add('allow-scripts')
13-
iframe.src = __TEMPLATE_isolation_src__
14-
document.body.append(iframe)
11+
let iframe = document.createElement('iframe')
12+
iframe.id = '__tauri_isolation__'
13+
iframe.sandbox.add('allow-scripts')
14+
iframe.src = __TEMPLATE_isolation_src__
15+
document.body.append(iframe)
16+
}
1517
})

core/tauri/src/hooks.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub(crate) struct IpcJavascript<'a> {
3939
#[derive(Template)]
4040
#[default_template("../scripts/isolation.js")]
4141
pub(crate) struct IsolationJavascript<'a> {
42+
pub(crate) origin: &'a str,
4243
pub(crate) isolation_src: &'a str,
4344
pub(crate) style: &'a str,
4445
}

core/tauri/src/manager.rs

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ impl<R: Runtime> WindowManager<R> {
438438
if let Pattern::Isolation { schema, .. } = self.pattern() {
439439
webview_attributes = webview_attributes.initialization_script(
440440
&IsolationJavascript {
441+
origin: &self.get_browser_origin(),
441442
isolation_src: &crate::pattern::format_real_schema(schema),
442443
style: tauri_utils::pattern::isolation::IFRAME_STYLE,
443444
}

0 commit comments

Comments
 (0)