windows smoke: opt-in WebView2 DevTools port via LOTUS_WEBVIEW2_DEBUG_PORT (#19)
WebView2's WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS is ignored because the app sets its browser arguments explicitly (seen on the runner: the WebView2 command line had only the app's arguments). The app now appends --remote-debugging-port only when LOTUS_WEBVIEW2_DEBUG_PORT holds a valid port (>= 1024); otherwise the arguments are exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
90c007a95e
commit
9f0f782bbb
@@ -95,7 +95,9 @@ jobs:
|
|||||||
Copy-Item scripts\windows-smoke.mjs smoke-deps\windows-smoke.mjs
|
Copy-Item scripts\windows-smoke.mjs smoke-deps\windows-smoke.mjs
|
||||||
# Same step as the test: a process started in an earlier step may be
|
# Same step as the test: a process started in an earlier step may be
|
||||||
# cleaned up when that step ends.
|
# cleaned up when that step ends.
|
||||||
$env:WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS = '--remote-debugging-port=9222 --use-fake-device-for-media-stream'
|
# The app sets its own WebView2 arguments, so WebView2's env var doesn't
|
||||||
|
# apply; the app opens the DevTools port itself when asked (#19).
|
||||||
|
$env:LOTUS_WEBVIEW2_DEBUG_PORT = '9222'
|
||||||
$app = Join-Path $env:LOCALAPPDATA 'Lotus Chat\cinny.exe'
|
$app = Join-Path $env:LOCALAPPDATA 'Lotus Chat\cinny.exe'
|
||||||
Start-Process $app
|
Start-Process $app
|
||||||
Start-Sleep -Seconds 15
|
Start-Sleep -Seconds 15
|
||||||
|
|||||||
+41
-3
@@ -1128,9 +1128,9 @@ pub fn run() {
|
|||||||
// Tauri's default WebView2 args (setting this overrides them) and
|
// Tauri's default WebView2 args (setting this overrides them) and
|
||||||
// appends the Chromium background-throttling disables. Windows-only
|
// appends the Chromium background-throttling disables. Windows-only
|
||||||
// in effect; harmless elsewhere. Does not block system sleep.
|
// in effect; harmless elsewhere. Does not block system sleep.
|
||||||
.additional_browser_args(
|
.additional_browser_args(&webview2_browser_args(
|
||||||
"--disable-features=msWebOOUI,msPdfOOUI --disable-background-timer-throttling --disable-renderer-backgrounding --disable-backgrounding-occluded-windows",
|
std::env::var("LOTUS_WEBVIEW2_DEBUG_PORT").ok().as_deref(),
|
||||||
)
|
))
|
||||||
.on_page_load(move |window, payload| {
|
.on_page_load(move |window, payload| {
|
||||||
if matches!(payload.event(), PageLoadEvent::Finished) {
|
if matches!(payload.event(), PageLoadEvent::Finished) {
|
||||||
// Reveal only on the FIRST settle: later page loads (e.g. a
|
// Reveal only on the FIRST settle: later page loads (e.g. a
|
||||||
@@ -1289,6 +1289,44 @@ pub fn run() {
|
|||||||
.expect("error while building tauri application");
|
.expect("error while building tauri application");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// WebView2 browser arguments. Setting them replaces Tauri's defaults, so
|
||||||
|
/// they're kept, plus the Chromium background-throttling disables (P5-42).
|
||||||
|
///
|
||||||
|
/// cinny-desktop #19: `LOTUS_WEBVIEW2_DEBUG_PORT=<port>` in the environment
|
||||||
|
/// opens WebView2's DevTools port on localhost so the Windows smoke test can
|
||||||
|
/// drive the installed app. WebView2's own `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS`
|
||||||
|
/// doesn't apply because the app sets its arguments explicitly. Off unless the
|
||||||
|
/// variable holds a valid port; only whoever launches the app can set it.
|
||||||
|
pub(crate) fn webview2_browser_args(debug_port: Option<&str>) -> String {
|
||||||
|
let mut args = String::from(
|
||||||
|
"--disable-features=msWebOOUI,msPdfOOUI --disable-background-timer-throttling --disable-renderer-backgrounding --disable-backgrounding-occluded-windows",
|
||||||
|
);
|
||||||
|
if let Some(port) = debug_port
|
||||||
|
.and_then(|p| p.trim().parse::<u16>().ok())
|
||||||
|
.filter(|p| *p >= 1024)
|
||||||
|
{
|
||||||
|
eprintln!("webview: DevTools port {port} open (LOTUS_WEBVIEW2_DEBUG_PORT)");
|
||||||
|
args.push_str(&format!(" --remote-debugging-port={port}"));
|
||||||
|
}
|
||||||
|
args
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod webview2_args_tests {
|
||||||
|
use super::webview2_browser_args;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn debug_port_only_when_asked_for_and_valid() {
|
||||||
|
let base = webview2_browser_args(None);
|
||||||
|
assert!(base.contains("--disable-renderer-backgrounding"));
|
||||||
|
assert!(!base.contains("remote-debugging"));
|
||||||
|
assert!(webview2_browser_args(Some("9222")).ends_with(" --remote-debugging-port=9222"));
|
||||||
|
for bad in ["", "abc", "80", "70000", "9222 --evil", "-1"] {
|
||||||
|
assert_eq!(webview2_browser_args(Some(bad)), base, "{bad}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tray_tests {
|
mod tray_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user