From 82210ff4fea893207e5bf3eb3b65ea249b04ab0c Mon Sep 17 00:00:00 2001 From: Chip Reed Date: Thu, 9 May 2024 16:29:12 +0200 Subject: [PATCH 1/4] disable injecting init scripts into subframes on macOS --- src/webview/webkitgtk/mod.rs | 4 +--- src/webview/webview2/mod.rs | 1 + src/webview/wkwebview/mod.rs | 6 ++---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/webview/webkitgtk/mod.rs b/src/webview/webkitgtk/mod.rs index 853bb30ec..e8d6a6a7a 100644 --- a/src/webview/webkitgtk/mod.rs +++ b/src/webview/webkitgtk/mod.rs @@ -423,9 +423,7 @@ impl InnerWebView { if let Some(manager) = self.webview.user_content_manager() { let script = UserScript::new( js, - // FIXME: We allow subframe injection because webview2 does and cannot be disabled (currently). - // once webview2 allows disabling all-frame script injection, TopFrame should be set - // if it does not break anything. (originally added for isolation pattern). + // TODO: feature to allow injecting into subframes UserContentInjectedFrames::TopFrame, UserScriptInjectionTime::Start, &[], diff --git a/src/webview/webview2/mod.rs b/src/webview/webview2/mod.rs index 14d86e272..c451b669a 100644 --- a/src/webview/webview2/mod.rs +++ b/src/webview/webview2/mod.rs @@ -798,6 +798,7 @@ window.addEventListener('mousemove', (e) => window.chrome.webview.postMessage('_ Ok(webview) } + // TODO: feature to allow injecting into (specific) subframes fn add_script_to_execute_on_document_created( webview: &ICoreWebView2, js: String, diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index 901dd13e3..28c1cf895 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -899,10 +899,8 @@ r#"Object.defineProperty(window, 'ipc', { unsafe { let userscript: id = msg_send![class!(WKUserScript), alloc]; let script: id = - // FIXME: We allow subframe injection because webview2 does and cannot be disabled (currently). - // once webview2 allows disabling all-frame script injection, forMainFrameOnly should be enabled - // if it does not break anything. (originally added for isolation pattern). - msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:0]; + // TODO: feature to allow injecting into subframes + msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:1]; let _: () = msg_send![self.manager, addUserScript: script]; } } From 1345a8fb07cd1cf52e7539e98021a21653ef2c97 Mon Sep 17 00:00:00 2001 From: Chip Reed Date: Thu, 9 May 2024 16:32:34 +0200 Subject: [PATCH 2/4] formatting --- src/webview/wkwebview/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index 28c1cf895..7c9ac0ee6 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -899,8 +899,8 @@ r#"Object.defineProperty(window, 'ipc', { unsafe { let userscript: id = msg_send![class!(WKUserScript), alloc]; let script: id = - // TODO: feature to allow injecting into subframes - msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:1]; + // TODO: feature to allow injecting into subframes + msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:1]; let _: () = msg_send![self.manager, addUserScript: script]; } } From 4aee669e482fb0bee4cd50e6816a717292733190 Mon Sep 17 00:00:00 2001 From: Chip Reed Date: Thu, 9 May 2024 16:33:51 +0200 Subject: [PATCH 3/4] formatting --- src/webview/wkwebview/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index 7c9ac0ee6..8582b9bdc 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -899,7 +899,7 @@ r#"Object.defineProperty(window, 'ipc', { unsafe { let userscript: id = msg_send![class!(WKUserScript), alloc]; let script: id = - // TODO: feature to allow injecting into subframes + // TODO: feature to allow injecting into subframes msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:1]; let _: () = msg_send![self.manager, addUserScript: script]; } From fbdfef71dd6e33f5a82e43bc0b542deb27eb638d Mon Sep 17 00:00:00 2001 From: Chip Reed Date: Thu, 9 May 2024 16:34:48 +0200 Subject: [PATCH 4/4] formatting --- src/webview/wkwebview/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index 8582b9bdc..f68684d6a 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -898,8 +898,8 @@ r#"Object.defineProperty(window, 'ipc', { // [manager addUserScript:[[WKUserScript alloc] initWithSource:[NSString stringWithUTF8String:js.c_str()] injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]] unsafe { let userscript: id = msg_send![class!(WKUserScript), alloc]; - let script: id = // TODO: feature to allow injecting into subframes + let script: id = msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:1]; let _: () = msg_send![self.manager, addUserScript: script]; }