BlueGit

ict rusty-teams

fix(sign-in): Teams behind Defender for Cloud Apps no longer hangs on the sign-in screen (#154)

metis Schelstraete Bart · pushed by metis

Authored 2026-11-29 · 2 days ago

Hash
c47a19747489a3e84bd2baa2a29c0c7e6870ab28
Parent
6dd18f36
9 files changed +292 −43
crates/app/src/linux_park.rs +3 −3
@@ -74,7 +74,7 @@ pub fn spawn(clock: Arc<ParkClock>, browser: browser::Browser, endpoint: &str) {
74 74 if !browser.teams_has_msal_cache().await || !clock.due(Instant::now()) {
75 75 continue;
76 76 }
77 match park(&transport).await {
77 match park(&transport, browser.behind_mcas()).await {
78 78 Ok(true) => log::info!("Teams tab parked"),
79 79 Ok(false) => {}
80 80 Err(error) => log::warn!("parking the Teams tab failed: {error}"),
@@ -83,13 +83,13 @@ pub fn spawn(clock: Arc<ParkClock>, browser: browser::Browser, endpoint: &str) {
83 83 });
84 84 }
85 85
86 async fn park(transport: &session::CdpTransport) -> session::Result<bool> {
86 async fn park(transport: &session::CdpTransport, mcas: bool) -> session::Result<bool> {
87 87 let app = session::App::Teams;
88 88 let Some((control, _)) = transport.open(app, false).await? else {
89 89 return Ok(false);
90 90 };
91 91 control
92 .call("Page.navigate", json!({ "url": app.park_url() }))
92 .call("Page.navigate", json!({ "url": app.park_url(mcas) }))
93 93 .await?;
94 94 Ok(true)
95 95 }
@@ -74,7 +74,7 @@ pub fn spawn(clock: Arc<ParkClock>, browser: browser::Browser, endpoint: &str) {
74 if !browser.teams_has_msal_cache().await || !clock.due(Instant::now()) {
74 if !browser.teams_has_msal_cache().await || !clock.due(Instant::now()) {
75 continue;
75 continue;
76 }
76 }
77 match park(&transport).await {
77 match park(&transport, browser.behind_mcas()).await {
78 Ok(true) => log::info!("Teams tab parked"),
78 Ok(true) => log::info!("Teams tab parked"),
79 Ok(false) => {}
79 Ok(false) => {}
80 Err(error) => log::warn!("parking the Teams tab failed: {error}"),
80 Err(error) => log::warn!("parking the Teams tab failed: {error}"),
@@ -83,13 +83,13 @@ pub fn spawn(clock: Arc<ParkClock>, browser: browser::Browser, endpoint: &str) {
83 });
83 });
84}
84}
85
85
86async fn park(transport: &session::CdpTransport) -> session::Result<bool> {
86async fn park(transport: &session::CdpTransport, mcas: bool) -> session::Result<bool> {
87 let app = session::App::Teams;
87 let app = session::App::Teams;
88 let Some((control, _)) = transport.open(app, false).await? else {
88 let Some((control, _)) = transport.open(app, false).await? else {
89 return Ok(false);
89 return Ok(false);
90 };
90 };
91 control
91 control
92 .call("Page.navigate", json!({ "url": app.park_url() }))
92 .call("Page.navigate", json!({ "url": app.park_url(mcas) }))
93 .await?;
93 .await?;
94 Ok(true)
94 Ok(true)
95}
95}
crates/browser/src/bidi_transport.rs +4 −2
@@ -52,7 +52,7 @@ impl BidiTransport {
52 52 }
53 53
54 54 fn is_app_url(app: App, url: &str) -> bool {
55 app.origins().iter().any(|origin| url.starts_with(origin))
55 app.is_app_url(url)
56 56 }
57 57
58 58 fn no_browser(error: BrowserError) -> Error {
@@ -102,7 +102,9 @@ impl Transport for BidiTransport {
102 102 return Ok(());
103 103 };
104 104 if app.is_park_url(&context.url) {
105 self.bidi.navigate(&context.id, app.start_url()).await
105 self.bidi
106 .navigate(&context.id, app.start_url_like(&context.url))
107 .await
106 108 } else {
107 109 let params = json!({"context": context.id, "wait": "none"});
108 110 self.bidi
@@ -52,7 +52,7 @@ impl BidiTransport {
52}
52}
53
53
54fn is_app_url(app: App, url: &str) -> bool {
54fn is_app_url(app: App, url: &str) -> bool {
55 app.origins().iter().any(|origin| url.starts_with(origin))
55 app.is_app_url(url)
56}
56}
57
57
58fn no_browser(error: BrowserError) -> Error {
58fn no_browser(error: BrowserError) -> Error {
@@ -102,7 +102,9 @@ impl Transport for BidiTransport {
102 return Ok(());
102 return Ok(());
103 };
103 };
104 if app.is_park_url(&context.url) {
104 if app.is_park_url(&context.url) {
105 self.bidi.navigate(&context.id, app.start_url()).await
105 self.bidi
106 .navigate(&context.id, app.start_url_like(&context.url))
107 .await
106 } else {
108 } else {
107 let params = json!({"context": context.id, "wait": "none"});
109 let params = json!({"context": context.id, "wait": "none"});
108 self.bidi
110 self.bidi
crates/browser/src/browser.rs +112 −16
@@ -77,6 +77,9 @@ struct Inner {
77 77 timeouts: Timeouts,
78 78 operation: Mutex<()>,
79 79 wanted: AtomicBool,
80 /// Teams of this profile runs behind the MCAS proxy, loaded from the marker next to the
81 /// mode file.
82 mcas: AtomicBool,
80 83 /// Set for a Firefox browser, which speaks WebDriver BiDi instead of CDP.
81 84 bidi: Option<Bidi>,
82 85 }
@@ -86,8 +89,28 @@ pub struct Browser {
86 89 inner: Arc<Inner>,
87 90 }
88 91
89 pub(crate) fn start_urls() -> Vec<String> {
90 APPS.iter().map(|app| app.start_url().to_owned()).collect()
92 /// Marker that Teams runs behind the MCAS proxy, next to the mode file
93 /// (`rusty-teams-chrome.mode` gives `rusty-teams-chrome.mcas`).
94 fn mcas_marker(config: &Config) -> std::path::PathBuf {
95 config.mode_file.with_extension("mcas")
96 }
97
98 fn write_mcas_marker(marker: &std::path::Path) -> std::io::Result<()> {
99 std::fs::write(marker, "mcas")
100 }
101
102 /// A marker that is gone already is fine.
103 fn remove_mcas_marker(marker: &std::path::Path) -> std::io::Result<()> {
104 match std::fs::remove_file(marker) {
105 Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()),
106 other => other,
107 }
108 }
109
110 pub(crate) fn start_urls(mcas: bool) -> Vec<String> {
111 APPS.iter()
112 .map(|app| app.start_url(mcas).to_owned())
113 .collect()
91 114 }
92 115
93 116 pub(crate) fn jitter_between(min: Duration, max: Duration, random: u64) -> Duration {
@@ -120,6 +143,7 @@ impl Browser {
120 143 timeouts: Timeouts,
121 144 ) -> Browser {
122 145 let bidi = (config.engine == Engine::Firefox).then(|| Bidi::new(config.port));
146 let mcas = AtomicBool::new(mcas_marker(&config).exists());
123 147 Browser {
124 148 inner: Arc::new(Inner {
125 149 bidi,
@@ -128,6 +152,7 @@ impl Browser {
128 152 timeouts,
129 153 operation: Mutex::new(()),
130 154 wanted: AtomicBool::new(false),
155 mcas,
131 156 }),
132 157 }
133 158 }
@@ -202,12 +227,52 @@ impl Browser {
202 227 }
203 228
204 229 pub async fn tabs(&self) -> Result<Vec<Tab>, BrowserError> {
205 if let Some(bidi) = &self.inner.bidi {
206 return bidi.tabs().await;
230 let tabs = if let Some(bidi) = &self.inner.bidi {
231 bidi.tabs().await?
232 } else {
233 let response =
234 http::request(self.inner.config.port, "GET", "/json/list", HTTP_TIMEOUT).await?;
235 targets::parse_tabs(&response.body)?
236 };
237 self.note_mcas(&tabs);
238 Ok(tabs)
239 }
240
241 /// Once Teams shows up behind the MCAS proxy, later launches and parking go there too.
242 /// The marker next to the mode file keeps that across app restarts.
243 fn note_mcas(&self, tabs: &[Tab]) {
244 if self.behind_mcas() || !targets::has_mcas_app_tab(tabs) {
245 return;
246 }
247 log::info!("Teams runs behind the Defender for Cloud Apps proxy: using the proxied origin");
248 self.inner.mcas.store(true, Ordering::SeqCst);
249 let marker = mcas_marker(&self.inner.config);
250 if let Err(error) = write_mcas_marker(&marker) {
251 log::warn!(
252 "could not remember the MCAS proxy in {}: {error}",
253 marker.display()
254 );
255 }
256 }
257
258 /// True when this profile's Teams runs behind the MCAS proxy: start and park go there.
259 pub fn behind_mcas(&self) -> bool {
260 self.inner.mcas.load(Ordering::SeqCst)
261 }
262
263 /// Teams signed in on its own host, so the MCAS proxy is not needed (anymore).
264 fn forget_mcas(&self) {
265 if !self.behind_mcas() {
266 return;
267 }
268 log::info!(
269 "Teams signed in without the Defender for Cloud Apps proxy: using the plain origin"
270 );
271 self.inner.mcas.store(false, Ordering::SeqCst);
272 let marker = mcas_marker(&self.inner.config);
273 if let Err(error) = remove_mcas_marker(&marker) {
274 log::warn!("could not remove {}: {error}", marker.display());
207 275 }
208 let response =
209 http::request(self.inner.config.port, "GET", "/json/list", HTTP_TIMEOUT).await?;
210 targets::parse_tabs(&response.body)
211 276 }
212 277
213 278 pub async fn ensure_running(&self) -> Result<(), BrowserError> {
@@ -238,7 +303,7 @@ impl Browser {
238 303 return self.open_tab(app).await;
239 304 };
240 305 if let Some(bidi) = &self.inner.bidi {
241 let navigate = bidi.navigate(&tab.id, app.start_url());
306 let navigate = bidi.navigate(&tab.id, app.start_url(self.behind_mcas()));
242 307 return tokio::time::timeout(CDP_TIMEOUT, navigate)
243 308 .await
244 309 .map_err(|_| BrowserError::Cdp("browsingContext.navigate timed out".into()))?;
@@ -250,7 +315,7 @@ impl Browser {
250 315 cdp_call(
251 316 &url,
252 317 "Page.navigate",
253 json!({ "url": app.start_url() }),
318 json!({ "url": app.start_url(self.behind_mcas()) }),
254 319 CDP_TIMEOUT,
255 320 )
256 321 .await
@@ -308,6 +373,16 @@ impl Browser {
308 373 if tab.parked {
309 374 return false;
310 375 }
376 let ready = self.page_sign_in_ready(tab).await;
377 // only forget when no tab at all is proxied, else a plain tab next to a proxied one
378 // would flip the flag on every poll
379 if ready && !targets::has_mcas_app_tab(&tabs) {
380 self.forget_mcas();
381 }
382 ready
383 }
384
385 async fn page_sign_in_ready(&self, tab: &Tab) -> bool {
311 386 let expression = crate::sign_in_ready::PAGE_EXPRESSION.as_str();
312 387 if let Some(bidi) = &self.inner.bidi {
313 388 let evaluate = tokio::time::timeout(
@@ -342,7 +417,9 @@ impl Browser {
342 417 }
343 418 self.inner.wanted.store(true, Ordering::SeqCst);
344 419 self.stop_locked(false).await?;
345 self.launch_with_urls_locked(false, start_urls()).await
420 // the window starts on the plain host, behind MCAS the sign-in redirects to the proxy
421 // by itself. So a user who is not behind MCAS anymore gets the plain origin back.
422 self.launch_with_urls_locked(false, start_urls(false)).await
346 423 }
347 424
348 425 pub async fn headless(&self) -> Result<(), BrowserError> {
@@ -447,11 +524,14 @@ impl Browser {
447 524
448 525 async fn open_tab(&self, app: App) -> Result<(), BrowserError> {
449 526 if let Some(bidi) = &self.inner.bidi {
450 return tokio::time::timeout(OPEN_TAB_TIMEOUT, bidi.open_tab(app.start_url()))
451 .await
452 .map_err(|_| BrowserError::Cdp("opening the app tab timed out".into()))?;
527 return tokio::time::timeout(
528 OPEN_TAB_TIMEOUT,
529 bidi.open_tab(app.start_url(self.behind_mcas())),
530 )
531 .await
532 .map_err(|_| BrowserError::Cdp("opening the app tab timed out".into()))?;
453 533 }
454 let path = format!("/json/new?{}", app.start_url());
534 let path = format!("/json/new?{}", app.start_url(self.behind_mcas()));
455 535 let response =
456 536 http::request(self.inner.config.port, "PUT", &path, OPEN_TAB_TIMEOUT).await?;
457 537 if response.status != 200 {
@@ -464,7 +544,8 @@ impl Browser {
464 544 }
465 545
466 546 async fn launch_locked(&self, headless: bool) -> Result<(), BrowserError> {
467 self.launch_with_urls_locked(headless, start_urls()).await
547 self.launch_with_urls_locked(headless, start_urls(self.behind_mcas()))
548 .await
468 549 }
469 550
470 551 async fn launch_with_urls_locked(
@@ -678,6 +759,21 @@ mod tests {
678 759
679 760 #[test]
680 761 fn only_teams_starts() {
681 assert_eq!(start_urls(), ["https://teams.cloud.microsoft/"]);
762 assert_eq!(start_urls(false), ["https://teams.cloud.microsoft/"]);
763 assert_eq!(start_urls(true), ["https://teams.cloud.microsoft.mcas.ms/"]);
764 }
765
766 #[test]
767 fn mcas_marker_sits_next_to_the_mode_file_and_comes_and_goes() {
768 let dir = tempfile::tempdir().unwrap();
769 let mode_file = dir.path().join("rusty-teams-chrome.mode");
770 let marker = mode_file.with_extension("mcas");
771 assert!(marker.ends_with("rusty-teams-chrome.mcas"));
772 write_mcas_marker(&marker).unwrap();
773 assert!(marker.exists());
774 remove_mcas_marker(&marker).unwrap();
775 assert!(!marker.exists());
776 // removing twice is not an error
777 remove_mcas_marker(&marker).unwrap();
682 778 }
683 779 }
@@ -77,6 +77,9 @@ struct Inner {
77 timeouts: Timeouts,
77 timeouts: Timeouts,
78 operation: Mutex<()>,
78 operation: Mutex<()>,
79 wanted: AtomicBool,
79 wanted: AtomicBool,
80 /// Teams of this profile runs behind the MCAS proxy, loaded from the marker next to the
81 /// mode file.
82 mcas: AtomicBool,
80 /// Set for a Firefox browser, which speaks WebDriver BiDi instead of CDP.
83 /// Set for a Firefox browser, which speaks WebDriver BiDi instead of CDP.
81 bidi: Option<Bidi>,
84 bidi: Option<Bidi>,
82}
85}
@@ -86,8 +89,28 @@ pub struct Browser {
86 inner: Arc<Inner>,
89 inner: Arc<Inner>,
87}
90}
88
91
89pub(crate) fn start_urls() -> Vec<String> {
92/// Marker that Teams runs behind the MCAS proxy, next to the mode file
90 APPS.iter().map(|app| app.start_url().to_owned()).collect()
93/// (`rusty-teams-chrome.mode` gives `rusty-teams-chrome.mcas`).
94fn mcas_marker(config: &Config) -> std::path::PathBuf {
95 config.mode_file.with_extension("mcas")
96}
97
98fn write_mcas_marker(marker: &std::path::Path) -> std::io::Result<()> {
99 std::fs::write(marker, "mcas")
100}
101
102/// A marker that is gone already is fine.
103fn remove_mcas_marker(marker: &std::path::Path) -> std::io::Result<()> {
104 match std::fs::remove_file(marker) {
105 Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()),
106 other => other,
107 }
108}
109
110pub(crate) fn start_urls(mcas: bool) -> Vec<String> {
111 APPS.iter()
112 .map(|app| app.start_url(mcas).to_owned())
113 .collect()
91}
114}
92
115
93pub(crate) fn jitter_between(min: Duration, max: Duration, random: u64) -> Duration {
116pub(crate) fn jitter_between(min: Duration, max: Duration, random: u64) -> Duration {
@@ -120,6 +143,7 @@ impl Browser {
120 timeouts: Timeouts,
143 timeouts: Timeouts,
121 ) -> Browser {
144 ) -> Browser {
122 let bidi = (config.engine == Engine::Firefox).then(|| Bidi::new(config.port));
145 let bidi = (config.engine == Engine::Firefox).then(|| Bidi::new(config.port));
146 let mcas = AtomicBool::new(mcas_marker(&config).exists());
123 Browser {
147 Browser {
124 inner: Arc::new(Inner {
148 inner: Arc::new(Inner {
125 bidi,
149 bidi,
@@ -128,6 +152,7 @@ impl Browser {
128 timeouts,
152 timeouts,
129 operation: Mutex::new(()),
153 operation: Mutex::new(()),
130 wanted: AtomicBool::new(false),
154 wanted: AtomicBool::new(false),
155 mcas,
131 }),
156 }),
132 }
157 }
133 }
158 }
@@ -202,12 +227,52 @@ impl Browser {
202 }
227 }
203
228
204 pub async fn tabs(&self) -> Result<Vec<Tab>, BrowserError> {
229 pub async fn tabs(&self) -> Result<Vec<Tab>, BrowserError> {
205 if let Some(bidi) = &self.inner.bidi {
230 let tabs = if let Some(bidi) = &self.inner.bidi {
206 return bidi.tabs().await;
231 bidi.tabs().await?
232 } else {
233 let response =
234 http::request(self.inner.config.port, "GET", "/json/list", HTTP_TIMEOUT).await?;
235 targets::parse_tabs(&response.body)?
236 };
237 self.note_mcas(&tabs);
238 Ok(tabs)
239 }
240
241 /// Once Teams shows up behind the MCAS proxy, later launches and parking go there too.
242 /// The marker next to the mode file keeps that across app restarts.
243 fn note_mcas(&self, tabs: &[Tab]) {
244 if self.behind_mcas() || !targets::has_mcas_app_tab(tabs) {
245 return;
246 }
247 log::info!("Teams runs behind the Defender for Cloud Apps proxy: using the proxied origin");
248 self.inner.mcas.store(true, Ordering::SeqCst);
249 let marker = mcas_marker(&self.inner.config);
250 if let Err(error) = write_mcas_marker(&marker) {
251 log::warn!(
252 "could not remember the MCAS proxy in {}: {error}",
253 marker.display()
254 );
255 }
256 }
257
258 /// True when this profile's Teams runs behind the MCAS proxy: start and park go there.
259 pub fn behind_mcas(&self) -> bool {
260 self.inner.mcas.load(Ordering::SeqCst)
261 }
262
263 /// Teams signed in on its own host, so the MCAS proxy is not needed (anymore).
264 fn forget_mcas(&self) {
265 if !self.behind_mcas() {
266 return;
267 }
268 log::info!(
269 "Teams signed in without the Defender for Cloud Apps proxy: using the plain origin"
270 );
271 self.inner.mcas.store(false, Ordering::SeqCst);
272 let marker = mcas_marker(&self.inner.config);
273 if let Err(error) = remove_mcas_marker(&marker) {
274 log::warn!("could not remove {}: {error}", marker.display());
207 }
275 }
208 let response =
209 http::request(self.inner.config.port, "GET", "/json/list", HTTP_TIMEOUT).await?;
210 targets::parse_tabs(&response.body)
211 }
276 }
212
277
213 pub async fn ensure_running(&self) -> Result<(), BrowserError> {
278 pub async fn ensure_running(&self) -> Result<(), BrowserError> {
@@ -238,7 +303,7 @@ impl Browser {
238 return self.open_tab(app).await;
303 return self.open_tab(app).await;
239 };
304 };
240 if let Some(bidi) = &self.inner.bidi {
305 if let Some(bidi) = &self.inner.bidi {
241 let navigate = bidi.navigate(&tab.id, app.start_url());
306 let navigate = bidi.navigate(&tab.id, app.start_url(self.behind_mcas()));
242 return tokio::time::timeout(CDP_TIMEOUT, navigate)
307 return tokio::time::timeout(CDP_TIMEOUT, navigate)
243 .await
308 .await
244 .map_err(|_| BrowserError::Cdp("browsingContext.navigate timed out".into()))?;
309 .map_err(|_| BrowserError::Cdp("browsingContext.navigate timed out".into()))?;
@@ -250,7 +315,7 @@ impl Browser {
250 cdp_call(
315 cdp_call(
251 &url,
316 &url,
252 "Page.navigate",
317 "Page.navigate",
253 json!({ "url": app.start_url() }),
318 json!({ "url": app.start_url(self.behind_mcas()) }),
254 CDP_TIMEOUT,
319 CDP_TIMEOUT,
255 )
320 )
256 .await
321 .await
@@ -308,6 +373,16 @@ impl Browser {
308 if tab.parked {
373 if tab.parked {
309 return false;
374 return false;
310 }
375 }
376 let ready = self.page_sign_in_ready(tab).await;
377 // only forget when no tab at all is proxied, else a plain tab next to a proxied one
378 // would flip the flag on every poll
379 if ready && !targets::has_mcas_app_tab(&tabs) {
380 self.forget_mcas();
381 }
382 ready
383 }
384
385 async fn page_sign_in_ready(&self, tab: &Tab) -> bool {
311 let expression = crate::sign_in_ready::PAGE_EXPRESSION.as_str();
386 let expression = crate::sign_in_ready::PAGE_EXPRESSION.as_str();
312 if let Some(bidi) = &self.inner.bidi {
387 if let Some(bidi) = &self.inner.bidi {
313 let evaluate = tokio::time::timeout(
388 let evaluate = tokio::time::timeout(
@@ -342,7 +417,9 @@ impl Browser {
342 }
417 }
343 self.inner.wanted.store(true, Ordering::SeqCst);
418 self.inner.wanted.store(true, Ordering::SeqCst);
344 self.stop_locked(false).await?;
419 self.stop_locked(false).await?;
345 self.launch_with_urls_locked(false, start_urls()).await
420 // the window starts on the plain host, behind MCAS the sign-in redirects to the proxy
421 // by itself. So a user who is not behind MCAS anymore gets the plain origin back.
422 self.launch_with_urls_locked(false, start_urls(false)).await
346 }
423 }
347
424
348 pub async fn headless(&self) -> Result<(), BrowserError> {
425 pub async fn headless(&self) -> Result<(), BrowserError> {
@@ -447,11 +524,14 @@ impl Browser {
447
524
448 async fn open_tab(&self, app: App) -> Result<(), BrowserError> {
525 async fn open_tab(&self, app: App) -> Result<(), BrowserError> {
449 if let Some(bidi) = &self.inner.bidi {
526 if let Some(bidi) = &self.inner.bidi {
450 return tokio::time::timeout(OPEN_TAB_TIMEOUT, bidi.open_tab(app.start_url()))
527 return tokio::time::timeout(
451 .await
528 OPEN_TAB_TIMEOUT,
452 .map_err(|_| BrowserError::Cdp("opening the app tab timed out".into()))?;
529 bidi.open_tab(app.start_url(self.behind_mcas())),
530 )
531 .await
532 .map_err(|_| BrowserError::Cdp("opening the app tab timed out".into()))?;
453 }
533 }
454 let path = format!("/json/new?{}", app.start_url());
534 let path = format!("/json/new?{}", app.start_url(self.behind_mcas()));
455 let response =
535 let response =
456 http::request(self.inner.config.port, "PUT", &path, OPEN_TAB_TIMEOUT).await?;
536 http::request(self.inner.config.port, "PUT", &path, OPEN_TAB_TIMEOUT).await?;
457 if response.status != 200 {
537 if response.status != 200 {
@@ -464,7 +544,8 @@ impl Browser {
464 }
544 }
465
545
466 async fn launch_locked(&self, headless: bool) -> Result<(), BrowserError> {
546 async fn launch_locked(&self, headless: bool) -> Result<(), BrowserError> {
467 self.launch_with_urls_locked(headless, start_urls()).await
547 self.launch_with_urls_locked(headless, start_urls(self.behind_mcas()))
548 .await
468 }
549 }
469
550
470 async fn launch_with_urls_locked(
551 async fn launch_with_urls_locked(
@@ -678,6 +759,21 @@ mod tests {
678
759
679 #[test]
760 #[test]
680 fn only_teams_starts() {
761 fn only_teams_starts() {
681 assert_eq!(start_urls(), ["https://teams.cloud.microsoft/"]);
762 assert_eq!(start_urls(false), ["https://teams.cloud.microsoft/"]);
763 assert_eq!(start_urls(true), ["https://teams.cloud.microsoft.mcas.ms/"]);
764 }
765
766 #[test]
767 fn mcas_marker_sits_next_to_the_mode_file_and_comes_and_goes() {
768 let dir = tempfile::tempdir().unwrap();
769 let mode_file = dir.path().join("rusty-teams-chrome.mode");
770 let marker = mode_file.with_extension("mcas");
771 assert!(marker.ends_with("rusty-teams-chrome.mcas"));
772 write_mcas_marker(&marker).unwrap();
773 assert!(marker.exists());
774 remove_mcas_marker(&marker).unwrap();
775 assert!(!marker.exists());
776 // removing twice is not an error
777 remove_mcas_marker(&marker).unwrap();
682 }
778 }
683}
779}
crates/browser/src/targets.rs +41 −2
@@ -8,6 +8,22 @@ use crate::error::BrowserError;
8 8 const LOGIN_HOSTS: [&str; 2] = ["login.microsoftonline.com", "login.live.com"];
9 9 /// Outlook tabs earlier versions opened next to Teams; nothing uses them any more.
10 10 const RETIRED_HOSTS: [&str; 2] = ["outlook.office.com", "outlook.cloud.microsoft"];
11 /// The real app host, also when a MCAS session proxy sits in front of it
12 /// (teams.cloud.microsoft.mcas.ms is teams.cloud.microsoft).
13 fn unproxied_host(host: &str) -> &str {
14 host.strip_suffix(session::MCAS_SUFFIX).unwrap_or(host)
15 }
16
17 /// True when an app tab is served through the MCAS proxy.
18 pub(crate) fn has_mcas_app_tab(tabs: &[Tab]) -> bool {
19 tabs.iter().any(|tab| {
20 tab.app.is_some()
21 && tab
22 .host
23 .as_deref()
24 .is_some_and(|host| unproxied_host(host) != host)
25 })
26 }
11 27
12 28 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
13 29 #[serde(rename_all = "lowercase")]
@@ -18,9 +34,10 @@ pub enum App {
18 34 pub const APPS: [App; 1] = [App::Teams];
19 35
20 36 impl App {
21 pub fn start_url(self) -> &'static str {
37 /// With `mcas` through the MCAS proxy, else on the app's own host.
38 pub fn start_url(self, mcas: bool) -> &'static str {
22 39 match self {
23 App::Teams => "https://teams.cloud.microsoft/",
40 App::Teams => session::App::Teams.start_url(mcas),
24 41 }
25 42 }
26 43
@@ -127,6 +144,7 @@ pub(crate) fn tab_from_url(id: String, url: &str) -> Tab {
127 144 let secure = https_host(url);
128 145 let app = secure
129 146 .as_deref()
147 .map(unproxied_host)
130 148 .and_then(|host| APPS.into_iter().find(|app| app.hosts().contains(&host)));
131 149 let login = secure
132 150 .as_deref()
@@ -257,6 +275,27 @@ mod tests {
257 275 );
258 276 }
259 277
278 #[test]
279 fn mcas_proxied_teams_host_is_teams() {
280 let list = r#"[
281 {"id":"M","type":"page","url":"https://teams.cloud.microsoft.mcas.ms/"},
282 {"id":"P","type":"page","url":"https://teams.cloud.microsoft.mcas.ms/robots.txt"},
283 {"id":"E","type":"page","url":"https://teams.cloud.microsoft.evil.example/"},
284 {"id":"N","type":"page","url":"https://evil.mcas.ms/"}
285 ]"#;
286 let tabs = parse_tabs(list.as_bytes()).unwrap();
287 assert_eq!(tabs[0].app, Some(App::Teams));
288 assert!(!tabs[0].parked);
289 assert_eq!(tabs[1].app, Some(App::Teams));
290 assert!(tabs[1].parked);
291 assert_eq!(tabs[2].app, None);
292 assert_eq!(tabs[3].app, None);
293 assert_eq!(login_state(&tabs), LoginState::NotRequired);
294 assert!(has_mcas_app_tab(&tabs[..1]));
295 assert!(!has_mcas_app_tab(&tabs[3..]));
296 assert!(!has_mcas_app_tab(&parse_tabs(LIST.as_bytes()).unwrap()));
297 }
298
260 299 fn page(id: &str, url: &str) -> Tab {
261 300 tab_from_url(id.to_owned(), url)
262 301 }
@@ -8,6 +8,22 @@ use crate::error::BrowserError;
8const LOGIN_HOSTS: [&str; 2] = ["login.microsoftonline.com", "login.live.com"];
8const LOGIN_HOSTS: [&str; 2] = ["login.microsoftonline.com", "login.live.com"];
9/// Outlook tabs earlier versions opened next to Teams; nothing uses them any more.
9/// Outlook tabs earlier versions opened next to Teams; nothing uses them any more.
10const RETIRED_HOSTS: [&str; 2] = ["outlook.office.com", "outlook.cloud.microsoft"];
10const RETIRED_HOSTS: [&str; 2] = ["outlook.office.com", "outlook.cloud.microsoft"];
11/// The real app host, also when a MCAS session proxy sits in front of it
12/// (teams.cloud.microsoft.mcas.ms is teams.cloud.microsoft).
13fn unproxied_host(host: &str) -> &str {
14 host.strip_suffix(session::MCAS_SUFFIX).unwrap_or(host)
15}
16
17/// True when an app tab is served through the MCAS proxy.
18pub(crate) fn has_mcas_app_tab(tabs: &[Tab]) -> bool {
19 tabs.iter().any(|tab| {
20 tab.app.is_some()
21 && tab
22 .host
23 .as_deref()
24 .is_some_and(|host| unproxied_host(host) != host)
25 })
26}
11
27
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
13#[serde(rename_all = "lowercase")]
29#[serde(rename_all = "lowercase")]
@@ -18,9 +34,10 @@ pub enum App {
18pub const APPS: [App; 1] = [App::Teams];
34pub const APPS: [App; 1] = [App::Teams];
19
35
20impl App {
36impl App {
21 pub fn start_url(self) -> &'static str {
37 /// With `mcas` through the MCAS proxy, else on the app's own host.
38 pub fn start_url(self, mcas: bool) -> &'static str {
22 match self {
39 match self {
23 App::Teams => "https://teams.cloud.microsoft/",
40 App::Teams => session::App::Teams.start_url(mcas),
24 }
41 }
25 }
42 }
26
43
@@ -127,6 +144,7 @@ pub(crate) fn tab_from_url(id: String, url: &str) -> Tab {
127 let secure = https_host(url);
144 let secure = https_host(url);
128 let app = secure
145 let app = secure
129 .as_deref()
146 .as_deref()
147 .map(unproxied_host)
130 .and_then(|host| APPS.into_iter().find(|app| app.hosts().contains(&host)));
148 .and_then(|host| APPS.into_iter().find(|app| app.hosts().contains(&host)));
131 let login = secure
149 let login = secure
132 .as_deref()
150 .as_deref()
@@ -257,6 +275,27 @@ mod tests {
257 );
275 );
258 }
276 }
259
277
278 #[test]
279 fn mcas_proxied_teams_host_is_teams() {
280 let list = r#"[
281 {"id":"M","type":"page","url":"https://teams.cloud.microsoft.mcas.ms/"},
282 {"id":"P","type":"page","url":"https://teams.cloud.microsoft.mcas.ms/robots.txt"},
283 {"id":"E","type":"page","url":"https://teams.cloud.microsoft.evil.example/"},
284 {"id":"N","type":"page","url":"https://evil.mcas.ms/"}
285 ]"#;
286 let tabs = parse_tabs(list.as_bytes()).unwrap();
287 assert_eq!(tabs[0].app, Some(App::Teams));
288 assert!(!tabs[0].parked);
289 assert_eq!(tabs[1].app, Some(App::Teams));
290 assert!(tabs[1].parked);
291 assert_eq!(tabs[2].app, None);
292 assert_eq!(tabs[3].app, None);
293 assert_eq!(login_state(&tabs), LoginState::NotRequired);
294 assert!(has_mcas_app_tab(&tabs[..1]));
295 assert!(!has_mcas_app_tab(&tabs[3..]));
296 assert!(!has_mcas_app_tab(&parse_tabs(LIST.as_bytes()).unwrap()));
297 }
298
260 fn page(id: &str, url: &str) -> Tab {
299 fn page(id: &str, url: &str) -> Tab {
261 tab_from_url(id.to_owned(), url)
300 tab_from_url(id.to_owned(), url)
262 }
301 }
crates/browser/tests/mock_server.rs +18 −0
@@ -502,3 +502,21 @@ async fn hung_stop_falls_back_to_kill_when_close_is_ignored() {
502 502 assert_eq!(*harness.launcher.kills.lock().unwrap(), 1);
503 503 assert_eq!(harness.launcher.requests.lock().unwrap().len(), 2);
504 504 }
505
506 #[tokio::test]
507 async fn the_mcas_proxy_is_remembered_per_profile_not_per_process() {
508 let proxied = harness().await;
509 let plain = harness().await;
510 proxied
511 .mock
512 .start(&["https://teams.cloud.microsoft.mcas.ms/v2/"])
513 .await;
514 plain.mock.start(&[TEAMS]).await;
515 proxied.browser.tabs().await.unwrap();
516 plain.browser.tabs().await.unwrap();
517 assert!(proxied.browser.behind_mcas());
518 assert!(proxied.mode_file.with_extension("mcas").exists());
519 // a second profile in the same process does not pick it up
520 assert!(!plain.browser.behind_mcas());
521 assert!(!plain.mode_file.with_extension("mcas").exists());
522 }
@@ -502,3 +502,21 @@ async fn hung_stop_falls_back_to_kill_when_close_is_ignored() {
502 assert_eq!(*harness.launcher.kills.lock().unwrap(), 1);
502 assert_eq!(*harness.launcher.kills.lock().unwrap(), 1);
503 assert_eq!(harness.launcher.requests.lock().unwrap().len(), 2);
503 assert_eq!(harness.launcher.requests.lock().unwrap().len(), 2);
504}
504}
505
506#[tokio::test]
507async fn the_mcas_proxy_is_remembered_per_profile_not_per_process() {
508 let proxied = harness().await;
509 let plain = harness().await;
510 proxied
511 .mock
512 .start(&["https://teams.cloud.microsoft.mcas.ms/v2/"])
513 .await;
514 plain.mock.start(&[TEAMS]).await;
515 proxied.browser.tabs().await.unwrap();
516 plain.browser.tabs().await.unwrap();
517 assert!(proxied.browser.behind_mcas());
518 assert!(proxied.mode_file.with_extension("mcas").exists());
519 // a second profile in the same process does not pick it up
520 assert!(!plain.browser.behind_mcas());
521 assert!(!plain.mode_file.with_extension("mcas").exists());
522}
crates/session/src/app.rs +104 −13
@@ -1,5 +1,8 @@
1 1 use serde::Deserialize;
2 2
3 /// Defender for Cloud Apps (Conditional Access App Control) proxies the app on `<host>.mcas.ms`.
4 pub const MCAS_SUFFIX: &str = ".mcas.ms";
5
3 6 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4 7 pub enum App {
5 8 Teams,
@@ -17,24 +20,61 @@ impl App {
17 20 }
18 21 }
19 22
20 pub fn start_url(self) -> &'static str {
21 match self {
22 App::Teams => "https://teams.cloud.microsoft/",
23 /// With `mcas` the URL goes through the MCAS proxy, where the MSAL cache of a proxied
24 /// tenant lives.
25 pub fn start_url(self, mcas: bool) -> &'static str {
26 match (self, mcas) {
27 (App::Teams, false) => "https://teams.cloud.microsoft/",
28 (App::Teams, true) => "https://teams.cloud.microsoft.mcas.ms/",
23 29 }
24 30 }
25 31
26 32 /// A static page on the app origin: keeps the MSAL cache reachable without running the app.
27 pub fn park_url(self) -> &'static str {
28 match self {
29 App::Teams => "https://teams.cloud.microsoft/robots.txt",
33 pub fn park_url(self, mcas: bool) -> &'static str {
34 match (self, mcas) {
35 (App::Teams, false) => "https://teams.cloud.microsoft/robots.txt",
36 (App::Teams, true) => "https://teams.cloud.microsoft.mcas.ms/robots.txt",
30 37 }
31 38 }
32 39
40 /// The start URL on the same origin as `tab_url`, so waking a parked tab keeps its cache.
41 pub fn start_url_like(self, tab_url: &str) -> &'static str {
42 self.start_url(is_mcas_url(tab_url))
43 }
44
33 45 pub fn is_park_url(self, url: &str) -> bool {
34 url.starts_with(self.park_url())
46 // both origins count, a tab parked before the switch must still be seen as parked
47 [self.park_url(false), self.park_url(true)]
48 .iter()
49 .any(|park| url.starts_with(park))
50 }
51
52 /// True when `url` is an https page on one of the app hosts, directly or through the
53 /// MCAS proxy. The host must match exactly, a look-alike host is not the app.
54 pub fn is_app_url(self, url: &str) -> bool {
55 let Ok(parsed) = url::Url::parse(url) else {
56 return false;
57 };
58 let Some(host) = parsed.host_str().filter(|_| parsed.scheme() == "https") else {
59 return false;
60 };
61 let host = host.strip_suffix(MCAS_SUFFIX).unwrap_or(host);
62 self.origins()
63 .iter()
64 .any(|origin| origin.strip_prefix("https://") == Some(host))
35 65 }
36 66 }
37 67
68 /// True when `url` is an https page on a host behind the MCAS proxy.
69 pub fn is_mcas_url(url: &str) -> bool {
70 url::Url::parse(url).is_ok_and(|parsed| {
71 parsed.scheme() == "https"
72 && parsed
73 .host_str()
74 .is_some_and(|host| host.len() > MCAS_SUFFIX.len() && host.ends_with(MCAS_SUFFIX))
75 })
76 }
77
38 78 impl std::fmt::Display for App {
39 79 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 80 formatter.write_str(match self {
@@ -60,12 +100,7 @@ pub struct Target {
60 100
61 101 pub fn find_app_tab(targets: &[Target], app: App) -> Option<&Target> {
62 102 targets.iter().find(|target| {
63 target.kind == "page"
64 && target.websocket_url.is_some()
65 && app
66 .origins()
67 .iter()
68 .any(|origin| target.url.starts_with(origin))
103 target.kind == "page" && target.websocket_url.is_some() && app.is_app_url(&target.url)
69 104 })
70 105 }
71 106
@@ -125,6 +160,62 @@ mod tests {
125 160 assert!(!App::Teams.is_park_url("https://teams.cloud.microsoft/v2/"));
126 161 }
127 162
163 #[test]
164 fn mcas_urls_go_through_the_proxy_and_both_park_urls_count() {
165 assert_eq!(
166 App::Teams.start_url(true),
167 "https://teams.cloud.microsoft.mcas.ms/"
168 );
169 assert_eq!(
170 App::Teams.park_url(true),
171 "https://teams.cloud.microsoft.mcas.ms/robots.txt"
172 );
173 assert_eq!(
174 App::Teams.start_url(false),
175 "https://teams.cloud.microsoft/"
176 );
177 assert_eq!(
178 App::Teams.start_url_like("https://teams.cloud.microsoft.mcas.ms/robots.txt"),
179 App::Teams.start_url(true)
180 );
181 assert_eq!(
182 App::Teams.start_url_like("https://teams.cloud.microsoft/robots.txt"),
183 App::Teams.start_url(false)
184 );
185 assert!(!is_mcas_url("http://teams.cloud.microsoft.mcas.ms/"));
186 assert!(!is_mcas_url("https://mcas.ms/"));
187 assert!(App::Teams.is_park_url("https://teams.cloud.microsoft.mcas.ms/robots.txt"));
188 assert!(App::Teams.is_park_url("https://teams.cloud.microsoft/robots.txt"));
189 assert!(!App::Teams.is_park_url("https://teams.cloud.microsoft.mcas.ms/v2/"));
190 }
191
192 #[test]
193 fn app_urls_need_an_exact_host() {
194 for url in [
195 "https://teams.cloud.microsoft/v2/",
196 "https://teams.microsoft.com/v2/",
197 "https://teams.cloud.microsoft.mcas.ms/",
198 "https://teams.cloud.microsoft.mcas.ms/robots.txt",
199 ] {
200 assert!(App::Teams.is_app_url(url), "{url}");
201 }
202 for url in [
203 "https://teams.cloud.microsoft.evil.example/",
204 "https://teams.cloud.microsoftevil.example/",
205 "https://evil.mcas.ms/",
206 "http://teams.cloud.microsoft/",
207 "https://login.microsoftonline.com/",
208 "about:blank",
209 ] {
210 assert!(!App::Teams.is_app_url(url), "{url}");
211 }
212 let look_alike: Vec<Target> = serde_json::from_str(
213 r#"[{"type":"page","url":"https://teams.cloud.microsoft.evil.example/","webSocketDebuggerUrl":"ws://x/1"}]"#,
214 )
215 .unwrap();
216 assert!(find_app_tab(&look_alike, App::Teams).is_none());
217 }
218
128 219 #[test]
129 220 fn detects_login_tab() {
130 221 let mut targets = targets();
@@ -1,5 +1,8 @@
1use serde::Deserialize;
1use serde::Deserialize;
2
2
3/// Defender for Cloud Apps (Conditional Access App Control) proxies the app on `<host>.mcas.ms`.
4pub const MCAS_SUFFIX: &str = ".mcas.ms";
5
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum App {
7pub enum App {
5 Teams,
8 Teams,
@@ -17,24 +20,61 @@ impl App {
17 }
20 }
18 }
21 }
19
22
20 pub fn start_url(self) -> &'static str {
23 /// With `mcas` the URL goes through the MCAS proxy, where the MSAL cache of a proxied
21 match self {
24 /// tenant lives.
22 App::Teams => "https://teams.cloud.microsoft/",
25 pub fn start_url(self, mcas: bool) -> &'static str {
26 match (self, mcas) {
27 (App::Teams, false) => "https://teams.cloud.microsoft/",
28 (App::Teams, true) => "https://teams.cloud.microsoft.mcas.ms/",
23 }
29 }
24 }
30 }
25
31
26 /// A static page on the app origin: keeps the MSAL cache reachable without running the app.
32 /// A static page on the app origin: keeps the MSAL cache reachable without running the app.
27 pub fn park_url(self) -> &'static str {
33 pub fn park_url(self, mcas: bool) -> &'static str {
28 match self {
34 match (self, mcas) {
29 App::Teams => "https://teams.cloud.microsoft/robots.txt",
35 (App::Teams, false) => "https://teams.cloud.microsoft/robots.txt",
36 (App::Teams, true) => "https://teams.cloud.microsoft.mcas.ms/robots.txt",
30 }
37 }
31 }
38 }
32
39
40 /// The start URL on the same origin as `tab_url`, so waking a parked tab keeps its cache.
41 pub fn start_url_like(self, tab_url: &str) -> &'static str {
42 self.start_url(is_mcas_url(tab_url))
43 }
44
33 pub fn is_park_url(self, url: &str) -> bool {
45 pub fn is_park_url(self, url: &str) -> bool {
34 url.starts_with(self.park_url())
46 // both origins count, a tab parked before the switch must still be seen as parked
47 [self.park_url(false), self.park_url(true)]
48 .iter()
49 .any(|park| url.starts_with(park))
50 }
51
52 /// True when `url` is an https page on one of the app hosts, directly or through the
53 /// MCAS proxy. The host must match exactly, a look-alike host is not the app.
54 pub fn is_app_url(self, url: &str) -> bool {
55 let Ok(parsed) = url::Url::parse(url) else {
56 return false;
57 };
58 let Some(host) = parsed.host_str().filter(|_| parsed.scheme() == "https") else {
59 return false;
60 };
61 let host = host.strip_suffix(MCAS_SUFFIX).unwrap_or(host);
62 self.origins()
63 .iter()
64 .any(|origin| origin.strip_prefix("https://") == Some(host))
35 }
65 }
36}
66}
37
67
68/// True when `url` is an https page on a host behind the MCAS proxy.
69pub fn is_mcas_url(url: &str) -> bool {
70 url::Url::parse(url).is_ok_and(|parsed| {
71 parsed.scheme() == "https"
72 && parsed
73 .host_str()
74 .is_some_and(|host| host.len() > MCAS_SUFFIX.len() && host.ends_with(MCAS_SUFFIX))
75 })
76}
77
38impl std::fmt::Display for App {
78impl std::fmt::Display for App {
39 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 formatter.write_str(match self {
80 formatter.write_str(match self {
@@ -60,12 +100,7 @@ pub struct Target {
60
100
61pub fn find_app_tab(targets: &[Target], app: App) -> Option<&Target> {
101pub fn find_app_tab(targets: &[Target], app: App) -> Option<&Target> {
62 targets.iter().find(|target| {
102 targets.iter().find(|target| {
63 target.kind == "page"
103 target.kind == "page" && target.websocket_url.is_some() && app.is_app_url(&target.url)
64 && target.websocket_url.is_some()
65 && app
66 .origins()
67 .iter()
68 .any(|origin| target.url.starts_with(origin))
69 })
104 })
70}
105}
71
106
@@ -125,6 +160,62 @@ mod tests {
125 assert!(!App::Teams.is_park_url("https://teams.cloud.microsoft/v2/"));
160 assert!(!App::Teams.is_park_url("https://teams.cloud.microsoft/v2/"));
126 }
161 }
127
162
163 #[test]
164 fn mcas_urls_go_through_the_proxy_and_both_park_urls_count() {
165 assert_eq!(
166 App::Teams.start_url(true),
167 "https://teams.cloud.microsoft.mcas.ms/"
168 );
169 assert_eq!(
170 App::Teams.park_url(true),
171 "https://teams.cloud.microsoft.mcas.ms/robots.txt"
172 );
173 assert_eq!(
174 App::Teams.start_url(false),
175 "https://teams.cloud.microsoft/"
176 );
177 assert_eq!(
178 App::Teams.start_url_like("https://teams.cloud.microsoft.mcas.ms/robots.txt"),
179 App::Teams.start_url(true)
180 );
181 assert_eq!(
182 App::Teams.start_url_like("https://teams.cloud.microsoft/robots.txt"),
183 App::Teams.start_url(false)
184 );
185 assert!(!is_mcas_url("http://teams.cloud.microsoft.mcas.ms/"));
186 assert!(!is_mcas_url("https://mcas.ms/"));
187 assert!(App::Teams.is_park_url("https://teams.cloud.microsoft.mcas.ms/robots.txt"));
188 assert!(App::Teams.is_park_url("https://teams.cloud.microsoft/robots.txt"));
189 assert!(!App::Teams.is_park_url("https://teams.cloud.microsoft.mcas.ms/v2/"));
190 }
191
192 #[test]
193 fn app_urls_need_an_exact_host() {
194 for url in [
195 "https://teams.cloud.microsoft/v2/",
196 "https://teams.microsoft.com/v2/",
197 "https://teams.cloud.microsoft.mcas.ms/",
198 "https://teams.cloud.microsoft.mcas.ms/robots.txt",
199 ] {
200 assert!(App::Teams.is_app_url(url), "{url}");
201 }
202 for url in [
203 "https://teams.cloud.microsoft.evil.example/",
204 "https://teams.cloud.microsoftevil.example/",
205 "https://evil.mcas.ms/",
206 "http://teams.cloud.microsoft/",
207 "https://login.microsoftonline.com/",
208 "about:blank",
209 ] {
210 assert!(!App::Teams.is_app_url(url), "{url}");
211 }
212 let look_alike: Vec<Target> = serde_json::from_str(
213 r#"[{"type":"page","url":"https://teams.cloud.microsoft.evil.example/","webSocketDebuggerUrl":"ws://x/1"}]"#,
214 )
215 .unwrap();
216 assert!(find_app_tab(&look_alike, App::Teams).is_none());
217 }
218
128 #[test]
219 #[test]
129 fn detects_login_tab() {
220 fn detects_login_tab() {
130 let mut targets = targets();
221 let mut targets = targets();
crates/session/src/lib.rs +1 −1
@@ -10,7 +10,7 @@ mod scope;
10 10 mod session;
11 11 mod transport;
12 12
13 pub use app::{App, Target, find_app_tab, has_login_tab, is_login_url};
13 pub use app::{App, MCAS_SUFFIX, Target, find_app_tab, has_login_tab, is_login_url, is_mcas_url};
14 14 pub use error::{Error, Result};
15 15 pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
16 16 pub use native::ensure_crypto_provider;
@@ -10,7 +10,7 @@ mod scope;
10mod session;
10mod session;
11mod transport;
11mod transport;
12
12
13pub use app::{App, Target, find_app_tab, has_login_tab, is_login_url};
13pub use app::{App, MCAS_SUFFIX, Target, find_app_tab, has_login_tab, is_login_url, is_mcas_url};
14pub use error::{Error, Result};
14pub use error::{Error, Result};
15pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
15pub use events::{TabChannel, TabCommand, TabControl, TabEvent, TabEvents};
16pub use native::ensure_crypto_provider;
16pub use native::ensure_crypto_provider;
crates/session/src/transport.rs +4 −1
@@ -79,7 +79,10 @@ impl Transport for CdpTransport {
79 79 open(target.websocket_url.as_deref().unwrap_or_default(), false).await?;
80 80 if parked {
81 81 control
82 .call("Page.navigate", json!({"url": app.start_url()}))
82 .call(
83 "Page.navigate",
84 json!({"url": app.start_url_like(&target.url)}),
85 )
83 86 .await?;
84 87 } else {
85 88 control
@@ -79,7 +79,10 @@ impl Transport for CdpTransport {
79 open(target.websocket_url.as_deref().unwrap_or_default(), false).await?;
79 open(target.websocket_url.as_deref().unwrap_or_default(), false).await?;
80 if parked {
80 if parked {
81 control
81 control
82 .call("Page.navigate", json!({"url": app.start_url()}))
82 .call(
83 "Page.navigate",
84 json!({"url": app.start_url_like(&target.url)}),
85 )
83 .await?;
86 .await?;
84 } else {
87 } else {
85 control
88 control
crates/webview/src/host.rs +5 −5
@@ -190,7 +190,7 @@ fn create_windows(title: &str) -> windows::core::Result<HashMap<App, HWND>> {
190 190 }
191 191
192 192 fn load(shared: &Rc<Shared>) {
193 match create_views(shared, |app| app.start_url()) {
193 match create_views(shared, |app| app.start_url(false)) {
194 194 Ok(()) => shared.state.send_modify(|state| {
195 195 state.ready = true;
196 196 state.failure = None;
@@ -342,7 +342,7 @@ fn park(shared: &Shared, app: App) {
342 342 {
343 343 set_memory_level(&webview, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW);
344 344 unsafe {
345 let _ = webview.Navigate(&HSTRING::from(app.park_url()));
345 let _ = webview.Navigate(&HSTRING::from(app.park_url(false)));
346 346 }
347 347 }
348 348 }
@@ -593,7 +593,7 @@ fn wake(shared: &Rc<Shared>, app: App) {
593 593 let _ = if is_running_app(app, &url) {
594 594 webview.Reload()
595 595 } else {
596 webview.Navigate(&HSTRING::from(app.start_url()))
596 webview.Navigate(&HSTRING::from(app.start_url(false)))
597 597 };
598 598 }
599 599 }
@@ -715,9 +715,9 @@ fn wake_views(shared: &Rc<Shared>, full: Option<App>) {
715 715 });
716 716 let outcome = create_views(shared, |app| {
717 717 if Some(app) == full {
718 app.start_url()
718 app.start_url(false)
719 719 } else {
720 app.park_url()
720 app.park_url(false)
721 721 }
722 722 });
723 723 if let Err(reason) = outcome {
@@ -190,7 +190,7 @@ fn create_windows(title: &str) -> windows::core::Result<HashMap<App, HWND>> {
190}
190}
191
191
192fn load(shared: &Rc<Shared>) {
192fn load(shared: &Rc<Shared>) {
193 match create_views(shared, |app| app.start_url()) {
193 match create_views(shared, |app| app.start_url(false)) {
194 Ok(()) => shared.state.send_modify(|state| {
194 Ok(()) => shared.state.send_modify(|state| {
195 state.ready = true;
195 state.ready = true;
196 state.failure = None;
196 state.failure = None;
@@ -342,7 +342,7 @@ fn park(shared: &Shared, app: App) {
342 {
342 {
343 set_memory_level(&webview, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW);
343 set_memory_level(&webview, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW);
344 unsafe {
344 unsafe {
345 let _ = webview.Navigate(&HSTRING::from(app.park_url()));
345 let _ = webview.Navigate(&HSTRING::from(app.park_url(false)));
346 }
346 }
347 }
347 }
348}
348}
@@ -593,7 +593,7 @@ fn wake(shared: &Rc<Shared>, app: App) {
593 let _ = if is_running_app(app, &url) {
593 let _ = if is_running_app(app, &url) {
594 webview.Reload()
594 webview.Reload()
595 } else {
595 } else {
596 webview.Navigate(&HSTRING::from(app.start_url()))
596 webview.Navigate(&HSTRING::from(app.start_url(false)))
597 };
597 };
598 }
598 }
599}
599}
@@ -715,9 +715,9 @@ fn wake_views(shared: &Rc<Shared>, full: Option<App>) {
715 });
715 });
716 let outcome = create_views(shared, |app| {
716 let outcome = create_views(shared, |app| {
717 if Some(app) == full {
717 if Some(app) == full {
718 app.start_url()
718 app.start_url(false)
719 } else {
719 } else {
720 app.park_url()
720 app.park_url(false)
721 }
721 }
722 });
722 });
723 if let Err(reason) = outcome {
723 if let Err(reason) = outcome {