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:
@@ -264,6 +264,7 @@ impl BotBrowser {
|
||||
pub async fn start(exe: &Path, profile: &Path, screen: Option<crate::vdisplay::Rect>) -> Result<Self, String> {
|
||||
let proxy = EgressProxy::start(is_public).await.map_err(|e| format!("proxy: {e}"))?;
|
||||
std::fs::create_dir_all(profile).map_err(|e| e.to_string())?;
|
||||
turn_off_translation(profile);
|
||||
let port_file = profile.join("DevToolsActivePort");
|
||||
let _ = std::fs::remove_file(&port_file);
|
||||
let no_sandbox = cfg!(not(windows)) && std::env::var("JARVIS_CHROME_NO_SANDBOX").is_ok_and(|v| v == "1");
|
||||
@@ -403,6 +404,25 @@ async fn kill_tree(child: &mut tokio::process::Child) {
|
||||
let _ = child.kill().await;
|
||||
}
|
||||
|
||||
/// Chrome no longer reads `--disable-features=Translate`: without this preference it offers to
|
||||
/// translate every page in another language, a bubble that covers the page on the shared screen.
|
||||
/// Written before Chrome starts; the profile's other preferences stay.
|
||||
fn turn_off_translation(profile: &Path) {
|
||||
let file = profile.join("Default").join("Preferences");
|
||||
let mut prefs = std::fs::read_to_string(&file).ok()
|
||||
.and_then(|t| serde_json::from_str::<serde_json::Value>(&t).ok())
|
||||
.filter(serde_json::Value::is_object).unwrap_or_else(|| serde_json::json!({}));
|
||||
if !prefs["translate"].is_object() {
|
||||
prefs["translate"] = serde_json::json!({});
|
||||
}
|
||||
prefs["translate"]["enabled"] = false.into();
|
||||
let written = std::fs::create_dir_all(file.parent().unwrap_or(profile))
|
||||
.and_then(|_| std::fs::write(&file, prefs.to_string()));
|
||||
if let Err(e) = written {
|
||||
crate::warn_log!("browser", "could not turn off translation in the profile: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the bot browser's profile lives in the data folder.
|
||||
pub fn profile_dir(data: &Path) -> PathBuf {
|
||||
data.join("browser").join("profile")
|
||||
@@ -497,6 +517,30 @@ mod tests {
|
||||
assert_eq!(seen[1], format!("GET /a/b?c=1 HTTP/1.1\r\nHost: 127.0.0.1:{port}\r\nAccept: */*\r\nConnection: close\r\n\r\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_profile_never_offers_to_translate_and_keeps_its_other_preferences() {
|
||||
let dir = std::env::temp_dir().join(format!("jarvis-translate-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let prefs = |d: &Path| -> serde_json::Value {
|
||||
serde_json::from_str(&std::fs::read_to_string(d.join("Default").join("Preferences")).unwrap()).unwrap()
|
||||
};
|
||||
turn_off_translation(&dir);
|
||||
assert_eq!(prefs(&dir)["translate"]["enabled"], false, "a new profile");
|
||||
|
||||
std::fs::write(dir.join("Default").join("Preferences"),
|
||||
r#"{"homepage":"x","translate":{"enabled":true,"blocked_languages":["ko"]}}"#).unwrap();
|
||||
turn_off_translation(&dir);
|
||||
let p = prefs(&dir);
|
||||
assert_eq!(p["translate"]["enabled"], false, "a profile Chrome already used");
|
||||
assert_eq!(p["homepage"], "x");
|
||||
assert_eq!(p["translate"]["blocked_languages"][0], "ko");
|
||||
|
||||
std::fs::write(dir.join("Default").join("Preferences"), "not json").unwrap();
|
||||
turn_off_translation(&dir);
|
||||
assert_eq!(prefs(&dir)["translate"]["enabled"], false, "a damaged file");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chrome_goes_through_the_proxy_with_its_own_profile() {
|
||||
let a = chrome_args(Path::new("/d/browser/profile"), 4321, false, false);
|
||||
|
||||
Reference in New Issue
Block a user