33import os
44import re
55from pathlib import Path
6- from selenium import webdriver
7- from selenium .webdriver .chrome .options import Options
86
97def get_app_name ():
108 """Get the app name from environment variable, falling back to default"""
@@ -67,22 +65,15 @@ def get_logout_url_from_unity_logs():
6765 return None
6866
6967def logout_with_controlled_browser ():
70- """Handle logout using the controlled browser instance instead of letting Unity open its own browser."""
68+ """Handle logout without relying on Selenium/ChromeDriver.
69+
70+ The Unity sample app already opens the logout URL in the system browser when LogoutBtn is tapped.
71+ Here we monitor Unity logs to capture that logout URL, extract its `returnTo` deep-link, and
72+ trigger it via `open` so Unity receives the callback deterministically.
73+ """
7174 print ("Starting controlled logout process..." )
72-
73- # Set up Chrome WebDriver options to connect to the existing browser instance
74- chrome_options = Options ()
75- chrome_options .add_experimental_option ("debuggerAddress" , "localhost:9222" )
76-
77- # Brave binary location on macOS
78- brave_path = "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
79- chrome_options .binary_location = brave_path
80-
75+
8176 try :
82- # Connect to the existing browser instance
83- driver = webdriver .Chrome (options = chrome_options )
84- print ("Connected to existing browser for logout" )
85-
8677 # Monitor Unity logs for logout URL
8778 print ("Monitoring Unity logs for logout URL..." )
8879 logout_url = None
@@ -93,17 +84,8 @@ def logout_with_controlled_browser():
9384 time .sleep (1 )
9485
9586 if logout_url :
96- print (f"Navigating controlled browser to logout URL: { logout_url } " )
97- driver .get (logout_url )
98-
99- # Wait for logout page to load
100- time .sleep (3 )
101- print ("Logout completed in controlled browser" )
102-
103- # Check final page
104- current_url = driver .current_url
105- print (f"Final logout URL: { current_url } " )
106-
87+ print (f"Captured logout URL from Unity logs: { logout_url } " )
88+
10789 # Extract the deep-link from the redirect
10890 # Look for immutablerunner://logout in the response or extract from returnTo parameter
10991 if 'returnTo=' in logout_url :
@@ -118,6 +100,10 @@ def logout_with_controlled_browser():
118100 print (f"Triggering deep-link manually: { return_to } " )
119101 subprocess .run (['open' , return_to ], check = False )
120102 time .sleep (2 )
103+ else :
104+ print ("Warning: returnTo parameter present but could not be parsed." )
105+ else :
106+ print ("Warning: logout URL did not include returnTo; cannot trigger deep-link callback." )
121107
122108 else :
123109 print ("Could not find logout URL in Unity logs - logout may complete without browser interaction" )
0 commit comments