Skip to content

Commit

Permalink
fix(core): nested isolation iframes, closes #4015 (#4020)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 1, 2022
1 parent 8f259f4 commit 022eed4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-nested-isolation-iframe.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fixes nested isolation iframe injection.
18 changes: 10 additions & 8 deletions core/tauri/scripts/isolation.js
Expand Up @@ -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)
}
})
1 change: 1 addition & 0 deletions core/tauri/src/hooks.rs
Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/manager.rs
Expand Up @@ -438,6 +438,7 @@ impl<R: Runtime> WindowManager<R> {
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,
}
Expand Down

0 comments on commit 022eed4

Please sign in to comment.