fix(browser): the shared bot browser never offers to translate, and its window check covers the focus

Chrome 157 no longer reads --disable-features=Translate, so on the virtual monitor every page in
another language got a translate bubble over it on the shared screen (seen on the game PC). The
profile's preferences now turn translation off before each start, keeping the other preferences.

The live screen test also checks that opening the window leaves the focus where it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-15 13:51:04 +09:00
parent f71c72d3a1
commit cb2dda25b6
3 changed files with 63 additions and 3 deletions

View File

@@ -86,9 +86,20 @@ async fn the_browser_step_installs_a_chrome_that_starts() {
let _ = std::fs::remove_dir_all(&data);
}
/// The process whose window has the keyboard focus (Windows).
#[cfg(windows)]
fn foreground_pid() -> u32 {
use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId};
let mut pid = 0;
// SAFETY: plain queries; `pid` outlives the call.
unsafe { GetWindowThreadProcessId(GetForegroundWindow(), &mut pid) };
pid
}
/// With a screen, Chrome starts without a window and the app opens exactly one, at the screen's
/// place and size; the page tab the bot opens joins it. Needs a display on Linux (`DISPLAY`); on
/// Windows the screen is the virtual monitor (its driver installed), on the desktop only meanwhile.
/// place and size, without taking the focus; the page tab the bot opens joins it. Needs a display
/// on Linux (`DISPLAY`); on Windows the screen is the virtual monitor (its driver installed), on the
/// desktop only meanwhile.
#[tokio::test]
async fn on_a_screen_the_bot_browser_has_one_window_at_the_monitor() {
let Ok(exe) = std::env::var("JARVIS_TEST_CHROME") else {
@@ -107,7 +118,11 @@ async fn on_a_screen_the_bot_browser_has_one_window_at_the_monitor() {
} else {
jarvis_app::vdisplay::Rect { x: 40, y: 30, w: 1280, h: 720 }
};
#[cfg(windows)]
let focused = foreground_pid();
let b = BotBrowser::start(std::path::Path::new(&exe), &profile, Some(screen)).await.expect("chrome starts");
#[cfg(windows)]
assert_eq!(foreground_pid(), focused, "opening the window leaves the focus where it was");
let client = reqwest::Client::builder().no_proxy().build().unwrap();
let pages = |l: serde_json::Value| l.as_array().unwrap().iter().filter(|t| t["type"] == "page")
.map(|t| t["id"].as_str().unwrap().to_owned()).collect::<Vec<_>>();