Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
0.9.1: TikTok sign-in no longer freezes on bytedance: (frame policy, one reload per app) (#522)
Oleksandr Ivanchenkobf9a9860b2fa
diff --git a/src/sandbox/app_links.rs b/src/sandbox/app_links.rsindex 4f4f9c47..f9c47566 100644--- a/src/sandbox/app_links.rs+++ b/src/sandbox/app_links.rs@@ -6,9 +6,15 @@//! it. It closes only on a cross-site navigation, so even a reload leaves the page dead.//!//! kwnt keeps it from opening in the first place: [`GUARD_JS`] runs in an isolated world of every-//! document and cancels a navigation to such a link before it reaches Chrome. What it can't-//! cancel (a frame whose first address is the link) is caught by [`AppLinkWatch`], which tells-//! the live view to step the tab off the page and back, the one thing that closes the prompt.+//! document and cancels a navigation to such a link before it reaches Chrome. A frame leaving its+//! first, empty document fires no `navigate` event, so the guard can't see that one: TikTok's+//! sign-in fires `bytedance://dispatch_message/` that way, from a hidden iframe it removes after+//! 300 ms, again on every new QR code. For frames the guard also gives every document a content+//! security policy that only lets frames load web pages ([`FRAME_POLICY`]): Chrome blocks such a+//! frame itself, before it would ask, and says so in its log ([`blocked_frame`]).+//! Anything that still gets past both is caught by [`AppLinkWatch`], which tells the live view+//! to step the tab off the page and back, the one thing that closes the prompt, once per app in+//! [`WINDOW`]: a page that opens the same app again on every load isn't reloaded in a loop.//! A link that fired while no live view was open is found when one opens: [`PROBE_ARM_JS`] and//! [`PROBE_READ_JS`] check that the page still gets a mouse move, and a tab that doesn't is//! stepped off and back the same way.@@ -31,7 +37,15 @@ const NO_PROMPT: &[&str] = &["mailto", "news", "snews"];/// Chrome's console line when it refuses a link outright (no user gesture) instead of asking.pub const REFUSED_LOG: &str = "Not allowed to launch";-/// Cancels navigations to another app in this document. Runs in [`WORLD`], once per world.+/// The content security policy every document gets: frames may load web pages (`*` is any+/// http(s) address or one of the page's own scheme) and what a tab opens itself, never another+/// app. Policies only add up, so a page's own policy still holds as it was.+pub const FRAME_POLICY: &str = "frame-src * data: blob: about: filesystem: chrome-extension:";++/// Cancels navigations to another app in this document, and sets [`FRAME_POLICY`] so a frame+/// can't load one either. Runs in [`WORLD`], once per world, before the page's own scripts.+/// The policy goes in as a `<meta>` at the top of `<head>` (as soon as there is one) and the+/// element is taken out again at once: the policy stays, and the page never sees the tag.pub const GUARD_JS: &str = r#"(() => {if (self.__kwntAppLinks || !self.navigation) return;self.__kwntAppLinks = true;@@ -43,13 +57,36 @@ pub const GUARD_JS: &str = r#"(() => {event.preventDefault();try { self.__BINDING__(scheme); } catch (e) {}});+ // a frame leaving its first, empty document fires no navigate event: Chrome blocks that one+ const policy = () => {+ const head = document.head;+ if (!head) return false;+ const meta = document.createElement('meta');+ meta.httpEquiv = 'Content-Security-Policy';+ meta.content = __FRAME_POLICY__;+ head.prepend(meta);+ meta.remove();+ return true;+ };+ if (!policy()) {+ const watch = new MutationObserver(() => { if (policy()) watch.disconnect(); });+ watch.observe(document, { childList: true, subtree: true });+ }})()"#;-/// [`GUARD_JS`] with its scheme list and binding filled in.+/// [`GUARD_JS`] with its scheme list, binding and policy filled in.pub fn guard_js() -> String {GUARD_JS.replace("__IN_BROWSER__", &serde_json::to_string(IN_BROWSER).unwrap_or_default()).replace("__BINDING__", BINDING)+ .replace("__FRAME_POLICY__", &serde_json::to_string(FRAME_POLICY).unwrap_or_default())+}++/// Whether Chrome logged `text` because [`FRAME_POLICY`] blocked a frame from opening another+/// app: "Framing '' violates the following Content Security Policy directive: "frame-src *"…".+/// Chrome didn't ask, so the page still takes input.+pub fn blocked_frame(text: &str) -> bool {+ text.starts_with("Framing '") && text.contains("Content Security Policy directive: \"frame-src")}/// The scheme of `url` when it opens another app, lowercased. A link the tab opens itself, or@@ -110,8 +147,8 @@ pub fn shown_scheme(raw: &str) -> Option<String> {/// How long after a link starts loading Chrome may still refuse it outright (no prompt).pub const SETTLE: Duration = Duration::from_millis(400);-/// At most this many recoveries in [`WINDOW`]: a page that opens its app again on every load-/// would otherwise be stepped off and back forever.+/// At most this many recoveries in [`WINDOW`], and at most one per app: a page that opens its+/// app again on every load would otherwise be stepped off and back forever.pub const MAX_RECOVERIES: usize = 3;pub const WINDOW: Duration = Duration::from_secs(60);/// The person is told about a stopped link at most this often.@@ -123,7 +160,8 @@ pub const NOTICE_GAP: Duration = Duration::from_secs(5);pub enum Verdict {/// Chrome is asking: step the tab off the page and back, then tell the person.Recover(Option<String>),- /// Chrome is asking again too often: leave the page as it is and tell the person why.+ /// Chrome is asking again too often, or again for an app it was just recovered from: leave+ /// the page as it is and tell the person why.GiveUp(Option<String>),}@@ -169,7 +207,8 @@ pub const PROBE_READ_JS: &str = r#"(() => {#[derive(Debug, Default)]pub struct AppLinkWatch {pending: Option<(String, Instant)>,- recoveries: VecDeque<Instant>,+ /// When each recovery in the last [`WINDOW`] ran, and for which app (`None`: a tab found stuck).+ recoveries: VecDeque<(Instant, Option<String>)>,noticed: Option<Instant>,}@@ -180,9 +219,10 @@ impl AppLinkWatch {if let Some(scheme) = prompting_scheme(url) { self.pending = Some((scheme, now + SETTLE)); }}- /// Chrome logged `text`. A refusal means it didn't ask, so the page still takes input.+ /// Chrome logged `text`. A refusal, or a frame [`FRAME_POLICY`] blocked, means it didn't+ /// ask, so the page still takes input.pub fn logged(&mut self, text: &str) {- if text.starts_with(REFUSED_LOG) { self.pending = None; }+ if text.starts_with(REFUSED_LOG) || blocked_frame(text) { self.pending = None; }}/// When [`Self::due`] has something to say.@@ -205,9 +245,11 @@ impl AppLinkWatch {}fn verdict(&mut self, scheme: Option<String>, now: Instant) -> Verdict {- while self.recoveries.front().is_some_and(|t| now.duration_since(*t) >= WINDOW) { self.recoveries.pop_front(); }- if self.recoveries.len() >= MAX_RECOVERIES { return Verdict::GiveUp(scheme); }- self.recoveries.push_back(now);+ while self.recoveries.front().is_some_and(|(t, _)| now.duration_since(*t) >= WINDOW) { self.recoveries.pop_front(); }+ // the page loads again on a recovery and opens the same app again: one reload is enough+ let again = scheme.is_some() && self.recoveries.iter().any(|(_, s)| *s == scheme);+ if again || self.recoveries.len() >= MAX_RECOVERIES { return Verdict::GiveUp(scheme); }+ self.recoveries.push_back((now, scheme.clone()));Verdict::Recover(scheme)}@@ -291,28 +333,79 @@ mod tests {fn a_prompt_is_recovered_after_it_settles_a_few_times_a_minute_at_most() {let mut watch = AppLinkWatch::default();let t = Instant::now();- for i in 0..MAX_RECOVERIES as u64 {- let at = t + Duration::from_secs(i);- watch.started("snssdk1233://login", at);- watch.started("tiktok://second-in-the-same-burst", at);+ let apps = ["snssdk1233", "tiktok", "zoommtg"];+ for (i, app) in apps.iter().enumerate() {+ let at = t + Duration::from_secs(i as u64);+ watch.started(&format!("{app}://login"), at);+ watch.started("intent://second-in-the-same-burst", at);assert_eq!(watch.due(at + SETTLE / 2), None, "Chrome may still refuse it");- assert_eq!(watch.due(at + SETTLE), Some(Verdict::Recover(Some("snssdk1233".into()))));+ assert_eq!(watch.due(at + SETTLE), Some(Verdict::Recover(Some(app.to_string()))));assert_eq!(watch.due(at + SETTLE), None, "once per link");}- watch.started("snssdk1233://login", t + Duration::from_secs(10));- assert_eq!(watch.due(t + Duration::from_secs(11)), Some(Verdict::GiveUp(Some("snssdk1233".into()))));+ assert_eq!(apps.len(), MAX_RECOVERIES);+ watch.started("itms-apps://x", t + Duration::from_secs(10));+ assert_eq!(watch.due(t + Duration::from_secs(11)), Some(Verdict::GiveUp(Some("itms-apps".into()))));// a minute after the first, one may run againwatch.started("snssdk1233://login", t + WINDOW);assert_eq!(watch.due(t + WINDOW + SETTLE), Some(Verdict::Recover(Some("snssdk1233".into()))));}+ #[test]+ fn a_page_that_opens_the_same_app_on_every_load_is_reloaded_once() {+ // TikTok's sign-in fires bytedance: on every new QR code, and a reload makes a new one+ let mut watch = AppLinkWatch::default();+ let t = Instant::now();+ let link = "bytedance://dispatch_message/";+ watch.started(link, t);+ assert_eq!(watch.due(t + SETTLE), Some(Verdict::Recover(Some("bytedance".into()))));+ for secs in [2, 5, 30, 59] {+ let at = t + Duration::from_secs(secs);+ watch.started(link, at);+ assert_eq!(watch.due(at + SETTLE), Some(Verdict::GiveUp(Some("bytedance".into()))), "{secs}s: not reloaded again");+ }+ // another app may still be recovered, and the same one once the window has passed+ watch.started("snssdk1233://login", t + Duration::from_secs(3));+ assert_eq!(watch.due(t + Duration::from_secs(4)), Some(Verdict::Recover(Some("snssdk1233".into()))));+ watch.started(link, t + WINDOW);+ assert_eq!(watch.due(t + WINDOW + SETTLE), Some(Verdict::Recover(Some("bytedance".into()))));+ }++ #[test]+ fn a_frame_the_policy_blocked_needs_no_recovery() {+ // Chrome 154's line when FRAME_POLICY blocks TikTok's hidden bytedance: frame+ let blocked = "Framing '' violates the following Content Security Policy directive: \"frame-src * data: blob: about: filesystem: chrome-extension:\". \+ The request has been blocked. Note that '*' matches only URLs with network schemes ('http', 'https', 'ws', 'wss'), or URLs whose scheme matches `self`'s scheme.";+ assert!(blocked_frame(blocked));+ for other in ["Framing 'https://a/' violates the following Content Security Policy directive: \"default-src 'self'\".",+ "Refused to load the script 'x' because it violates the following Content Security Policy directive: \"frame-src *\"", "Not allowed to launch 'x:'", ""] {+ assert!(!blocked_frame(other), "{other}");+ }+ let mut watch = AppLinkWatch::default();+ let t = Instant::now();+ watch.started("bytedance://dispatch_message/", t);+ watch.logged(blocked);+ assert_eq!(watch.deadline(), None);+ assert_eq!(watch.due(t + SETTLE), None);+ }++ #[test]+ fn the_guard_keeps_frames_to_web_pages_only() {+ let js = guard_js();+ assert!(js.contains(&format!("meta.content = {};", serde_json::to_string(FRAME_POLICY).unwrap())), "{js}");+ assert!(js.contains("'Content-Security-Policy'") && js.contains("meta.remove()") && js.contains("MutationObserver"));+ // the policy names no app scheme and every frame scheme the tab opens itself+ assert!(FRAME_POLICY.starts_with("frame-src * "));+ for scheme in ["data:", "blob:", "about:", "filesystem:", "chrome-extension:"] { assert!(FRAME_POLICY.contains(scheme), "{scheme}"); }+ assert!(!js.contains("__FRAME_POLICY__"));+ }+#[test]fn a_tab_found_stuck_is_recovered_under_the_same_cap() {let mut watch = AppLinkWatch::default();let t = Instant::now();assert_eq!(watch.stuck(t), Verdict::Recover(None));for i in 1..MAX_RECOVERIES as u64 {- watch.started("snssdk1233://login", t + Duration::from_secs(i));+ watch.started(&format!("app{i}://login"), t + Duration::from_secs(i));assert!(matches!(watch.due(t + Duration::from_secs(i) + SETTLE), Some(Verdict::Recover(_))));}assert_eq!(watch.stuck(t + Duration::from_secs(10)), Verdict::GiveUp(None));diff --git a/src/server/browser_stream.rs b/src/server/browser_stream.rsindex 184df70c..64d60eb0 100644--- a/src/server/browser_stream.rs+++ b/src/server/browser_stream.rs@@ -291,7 +291,7 @@ fn wanted(event: &Value) -> bool {let method = event["method"].as_str().unwrap_or_default();match method {"Runtime.bindingCalled" => event["params"]["name"] == app_links::BINDING || event["params"]["name"] == recorder::BINDING,- "Log.entryAdded" => event["params"]["entry"]["text"].as_str().is_some_and(|text| text.starts_with(app_links::REFUSED_LOG)),+ "Log.entryAdded" => event["params"]["entry"]["text"].as_str().is_some_and(|text| text.starts_with(app_links::REFUSED_LOG) || app_links::blocked_frame(text)),_ => !method.starts_with("Runtime.") && !method.starts_with("Log."),}}diff --git a/tests/browser_app_links_test.rs b/tests/browser_app_links_test.rsnew file mode 100644index 00000000..2819d918--- /dev/null+++ b/tests/browser_app_links_test.rs@@ -0,0 +1,154 @@+//! Links to another app fired the way TikTok's sign-in fires `bytedance://dispatch_message/`, in+//! a real Chrome: a hidden iframe whose address is set right after it is added, so it leaves its+//! first, empty document, which fires no `navigate` event for kwnt's guard to cancel. Without the+//! guard's frame policy Chrome stops passing clicks and keys to the tab while it asks whether to+//! open the app; with it, Chrome blocks the frame and the page keeps taking input. Skipped when no+//! Chrome is installed.+#[path = "support/chrome_guard.rs"]+mod chrome_guard;+use chrome_guard::ChromeGuard;+use kwnt::{+ broker::PermissionBroker,+ config::Config,+ db::{models::Kwant, spaces::SpaceId, Database},+ router::LayaRouter,+ sandbox::{app_links, computer, BrowserController},+ server::{routes::get_or_create_browser_controller, AppState},+ tools::ToolRunner,+};+use serde_json::{json, Value};+use std::time::Duration;+use tempfile::{tempdir, TempDir};+use tokio::io::{AsyncReadExt, AsyncWriteExt};++/// TikTok's captcha bridge, as it sends a message to the app: a hidden iframe, then its address.+const BRIDGE: &str = "var t=document.createElement('iframe');t.style.display='none';document.body.appendChild(t);t.src='bytedance://dispatch_message/';";+/// A page that fires the bridge once it has loaded, with a button over the whole page.+const AFTER_LOAD: &str = "<!doctype html><html><head><title>sign in</title></head><body>\+<button id=b onclick=\"document.title='clicked'\" style='position:fixed;inset:0'>Log in</button>\+<script>setTimeout(function(){__BRIDGE__ document.title='fired'}, 300)</script></body></html>";+/// The same from a script in `<head>`, while the page is still loading.+const WHILE_LOADING: &str = "<!doctype html><html><head><title>sign in</title>\+<script>document.addEventListener('DOMContentLoaded', function(){__BRIDGE__ document.title='fired'})</script></head><body>\+<button id=b onclick=\"document.title='clicked'\" style='position:fixed;inset:0'>Log in</button></body></html>";+/// Frames the tab opens itself still load: each tells the page it did.+const FRAMES: &str = "<!doctype html><html><head><title>frames</title></head><body><script>\+var got=[];addEventListener('message',function(e){got.push(String(e.data));document.title=got.sort().join(',')});\+function add(k,v){var f=document.createElement('iframe');f[k]=v;document.body.appendChild(f)}\+add('srcdoc',\"<script>parent.postMessage('srcdoc','*')<\\/script>\");\+add('src',\"data:text/html,<script>parent.postMessage('data','*')<\\/script>\");\+add('src',URL.createObjectURL(new Blob([\"<script>parent.postMessage('blob','*')<\\/script>\"],{type:'text/html'})));\+add('src','/child');\+</script></body></html>";+const CHILD: &str = "<!doctype html><script>parent.postMessage('web','*')</script>";++async fn serve() -> String {+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();+ let port = listener.local_addr().unwrap().port();+ tokio::spawn(async move {+ while let Ok((mut stream, _)) = listener.accept().await {+ tokio::spawn(async move {+ let mut buf = [0u8; 4096];+ let n = stream.read(&mut buf).await.unwrap_or(0);+ let req = String::from_utf8_lossy(&buf[..n]).to_string();+ let path = req.split_whitespace().nth(1).unwrap_or("/").to_string();+ let page = match path.as_str() {+ "/after-load" => AFTER_LOAD.replace("__BRIDGE__", BRIDGE),+ "/while-loading" => WHILE_LOADING.replace("__BRIDGE__", BRIDGE),+ "/frames" => FRAMES.to_string(),+ "/child" => CHILD.to_string(),+ _ => "<!doctype html><title>plain</title>".to_string(),+ };+ let reply = format!("HTTP/1.1 200 OK\r\ncontent-type: text/html\r\ncontent-length: {}\r\nconnection: close\r\n\r\n{page}", page.len());+ let _ = stream.write_all(reply.as_bytes()).await;+ });+ }+ });+ format!("http://127.0.0.1:{port}")+}++struct Env {+ state: AppState,+ bot: Kwant,+ tmp: TempDir,+}++/// kwnt in Local mode, so the bot's browser is a real Chrome on this machine.+async fn setup() -> Env {+ let tmp = tempdir().unwrap();+ let db = Database::init(tmp.path()).await.unwrap();+ db.set_setting(computer::SETTING_KEY, "local").await.unwrap();+ let config = Config { data_dir: tmp.path().to_path_buf(), ..Config::default() };+ let state = AppState::new(config.clone(), db, ToolRunner::new(tmp.path().join("workspace")), PermissionBroker::new(), LayaRouter::new(config.laya_url.clone()));+ let bot = state.db.list_kwants(&SpaceId::default_space()).await.unwrap()[0].clone();+ Env { state, bot, tmp }+}++/// A DevTools command that gives up after a few seconds instead of hanging the test.+async fn cdp(ctrl: &BrowserController, method: &str, params: Value) -> Value {+ tokio::time::timeout(Duration::from_secs(10), ctrl.send_cdp_command(method, params))+ .await+ .unwrap_or_else(|_| panic!("{method} timed out"))+ .unwrap_or_else(|e| panic!("{method}: {e}"))+}++async fn eval(ctrl: &BrowserController, js: &str) -> Value {+ cdp(ctrl, "Runtime.evaluate", json!({"expression": js, "returnByValue": true})).await["result"]["value"].clone()+}++async fn title_becomes(ctrl: &BrowserController, want: &str) -> String {+ let mut title = String::new();+ for _ in 0..50 {+ title = eval(ctrl, "document.title").await.as_str().unwrap_or_default().to_string();+ if title == want { break; }+ tokio::time::sleep(Duration::from_millis(100)).await;+ }+ title+}++/// How many of a few mouse moves reach the page, with the live view's own input probe.+async fn moves_reaching(ctrl: &BrowserController) -> i64 {+ let point = eval(ctrl, app_links::PROBE_ARM_JS).await;+ let (x, y) = (point[0].as_f64().expect("a point to probe"), point[1].as_f64().unwrap());+ for dx in 0..5 {+ cdp(ctrl, "Input.dispatchMouseEvent", json!({"type": "mouseMoved", "x": x + dx as f64, "y": y, "button": "none", "buttons": 0})).await;+ }+ tokio::time::sleep(Duration::from_millis(200)).await;+ eval(ctrl, app_links::PROBE_READ_JS).await.as_i64().unwrap()+}++#[tokio::test]+async fn a_hidden_frame_opening_another_app_leaves_the_page_taking_input() {+ if computer::local_chrome_path().is_none() {+ eprintln!("skipped: no Chrome or Chromium installed");+ return;+ }+ let e = setup().await;+ let _chrome = ChromeGuard(e.tmp.path().join("local-chrome"));+ let base = serve().await;+ let ctrl = get_or_create_browser_controller(&e.state, &e.bot.id).await.expect("local Chrome session");+ for page in ["after-load", "while-loading"] {+ ctrl.navigate(&format!("{base}/{page}")).await.unwrap();+ assert_eq!(title_becomes(&ctrl, "fired").await, "fired", "{page}: the bridge ran");+ // Chrome takes well under a second to ask; give it more+ tokio::time::sleep(Duration::from_millis(2500)).await;+ assert_eq!(moves_reaching(&ctrl).await, 5, "{page}: every move reaches the page after the link fired");+ cdp(&ctrl, "Input.dispatchMouseEvent", json!({"type": "mousePressed", "x": 40, "y": 40, "button": "left", "buttons": 1, "clickCount": 1})).await;+ cdp(&ctrl, "Input.dispatchMouseEvent", json!({"type": "mouseReleased", "x": 40, "y": 40, "button": "left", "buttons": 0, "clickCount": 1})).await;+ assert_eq!(title_becomes(&ctrl, "clicked").await, "clicked", "{page}: a click still works");+ }+}++#[tokio::test]+async fn frames_the_tab_opens_itself_still_load_under_the_guard() {+ if computer::local_chrome_path().is_none() {+ eprintln!("skipped: no Chrome or Chromium installed");+ return;+ }+ let e = setup().await;+ let _chrome = ChromeGuard(e.tmp.path().join("local-chrome"));+ let base = serve().await;+ let ctrl = get_or_create_browser_controller(&e.state, &e.bot.id).await.expect("local Chrome session");+ ctrl.navigate(&format!("{base}/frames")).await.unwrap();+ assert_eq!(title_becomes(&ctrl, "blob,data,srcdoc,web").await, "blob,data,srcdoc,web");+}diff --git a/tests/browser_stream_test.rs b/tests/browser_stream_test.rsindex 4065981f..fa9a3bb7 100644--- a/tests/browser_stream_test.rs+++ b/tests/browser_stream_test.rs@@ -739,6 +739,14 @@ async fn a_link_to_another_app_is_stopped_or_its_prompt_closed_so_the_tab_keeps_push_event(&mock, "Log.entryAdded", json!({"entry":{"source":"other","level":"error","text":"Not allowed to launch 'snssdk1233://login?a=1' because a user gesture is required."}})).await;tokio::time::sleep(Duration::from_millis(900)).await;assert!(!mock.commands.lock().await.iter().any(|c| c["method"] == "Page.navigate"), "the page was left alone");+ assert!(guard["params"]["source"].as_str().unwrap().contains("Content-Security-Policy"), "frames may load web pages only");++ // TikTok's hidden bytedance: frame, which the guard's frame policy blocked: Chrome didn't ask+ push_event(&mock, "Page.frameRequestedNavigation", json!({"frameId":"F3","url":"bytedance://dispatch_message/","reason":"scriptInitiated","disposition":"currentTab"})).await;+ push_event(&mock, "Page.frameStartedNavigating", json!({"frameId":"F3","url":"bytedance://dispatch_message/","loaderId":"L3","navigationType":"differentDocument"})).await;+ push_event(&mock, "Log.entryAdded", json!({"entry":{"source":"security","level":"error","text":"Framing '' violates the following Content Security Policy directive: \"frame-src * data: blob: about: filesystem: chrome-extension:\". The request has been blocked."}})).await;+ tokio::time::sleep(Duration::from_millis(900)).await;+ assert!(!mock.commands.lock().await.iter().any(|c| c["method"] == "Page.navigate"), "a blocked frame isn't reloaded");// one got past the guard (a frame whose first address is the link): Chrome is asking, so the// tab steps off to about:blank and straight back to the sign-in page, which closes the prompt@@ -748,6 +756,13 @@ async fn a_link_to_another_app_is_stopped_or_its_prompt_closed_so_the_tab_keeps_let steps: Vec<Value> = mock.commands.lock().await.iter().filter(|c| matches!(c["method"].as_str(), Some("Page.navigate" | "Page.navigateToHistoryEntry"))).map(|c| c["params"].clone()).collect();assert_eq!(steps, vec![json!({"url":"about:blank"}), json!({"entryId":2})]);++ // the page loaded again and opened the same app again: it isn't reloaded in a loop+ push_event(&mock, "Page.frameStartedNavigating", json!({"frameId":"F4","url":"snssdk1233://login?c=1","loaderId":"L4","navigationType":"differentDocument"})).await;+ let gave_up = app_link_notice(&mut ws, Duration::from_secs(5)).await.expect("told why it wasn't reloaded");+ assert!(gave_up.contains("(snssdk1233:)") && !gave_up.contains("reloaded"), "{gave_up}");+ let steps = mock.commands.lock().await.iter().filter(|c| matches!(c["method"].as_str(), Some("Page.navigate" | "Page.navigateToHistoryEntry"))).count();+ assert_eq!(steps, 2, "no second reload");app_task.abort(); cdp_task.abort();}