From 022eed46675976e8dfe5f352a875754b4bd78131 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 1 May 2022 11:50:17 -0700 Subject: [PATCH] fix(core): nested isolation iframes, closes #4015 (#4020) --- .changes/fix-nested-isolation-iframe.md | 5 +++++ core/tauri/scripts/isolation.js | 18 ++++++++++-------- core/tauri/src/hooks.rs | 1 + core/tauri/src/manager.rs | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 .changes/fix-nested-isolation-iframe.md diff --git a/.changes/fix-nested-isolation-iframe.md b/.changes/fix-nested-isolation-iframe.md new file mode 100644 index 000000000..8283ad6ad --- /dev/null +++ b/.changes/fix-nested-isolation-iframe.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Fixes nested isolation iframe injection. diff --git a/core/tauri/scripts/isolation.js b/core/tauri/scripts/isolation.js index 7bb0e6df2..fa7e79551 100644 --- a/core/tauri/scripts/isolation.js +++ b/core/tauri/scripts/isolation.js @@ -3,13 +3,15 @@ // SPDX-License-Identifier: MIT window.addEventListener('DOMContentLoaded', () => { - let style = document.createElement('style') - style.textContent = __TEMPLATE_style__ - document.head.append(style) + if (window.location.origin.startsWith(__TEMPLATE_origin__)) { + let style = document.createElement('style') + style.textContent = __TEMPLATE_style__ + document.head.append(style) - let iframe = document.createElement('iframe') - iframe.id = '__tauri_isolation__' - iframe.sandbox.add('allow-scripts') - iframe.src = __TEMPLATE_isolation_src__ - document.body.append(iframe) + let iframe = document.createElement('iframe') + iframe.id = '__tauri_isolation__' + iframe.sandbox.add('allow-scripts') + iframe.src = __TEMPLATE_isolation_src__ + document.body.append(iframe) + } }) diff --git a/core/tauri/src/hooks.rs b/core/tauri/src/hooks.rs index 5f3495a60..309d9b39b 100644 --- a/core/tauri/src/hooks.rs +++ b/core/tauri/src/hooks.rs @@ -39,6 +39,7 @@ pub(crate) struct IpcJavascript<'a> { #[derive(Template)] #[default_template("../scripts/isolation.js")] pub(crate) struct IsolationJavascript<'a> { + pub(crate) origin: &'a str, pub(crate) isolation_src: &'a str, pub(crate) style: &'a str, } diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index e6b26620e..5c422d225 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -438,6 +438,7 @@ impl WindowManager { if let Pattern::Isolation { schema, .. } = self.pattern() { webview_attributes = webview_attributes.initialization_script( &IsolationJavascript { + origin: &self.get_browser_origin(), isolation_src: &crate::pattern::format_real_schema(schema), style: tauri_utils::pattern::isolation::IFRAME_STYLE, }