@@ -86,6 +86,82 @@ def get_auth_url_from_unity_logs():
8686 print ("No auth URL found in Unity logs" )
8787 return None
8888
89+ def get_logout_url_from_unity_logs ():
90+ """Monitor Unity logs to capture logout URLs."""
91+ import tempfile
92+ import os
93+
94+ # Unity log file locations on Windows
95+ log_paths = [
96+ os .path .join (os .path .expanduser ("~" ), "AppData" , "LocalLow" , "Immutable" , "Immutable Sample" , "Player.log" ),
97+ os .path .join (tempfile .gettempdir (), "UnityPlayer.log" ),
98+ "Player.log" # Current directory
99+ ]
100+
101+ for log_path in log_paths :
102+ if os .path .exists (log_path ):
103+ print (f"Monitoring Unity log for logout URL: { log_path } " )
104+ try :
105+ with open (log_path , 'r' , encoding = 'utf-8' , errors = 'ignore' ) as f :
106+ content = f .read ()
107+ # Look for logout URLs in Unity logs
108+ matches = re .findall (r'(?:PASSPORT_LOGOUT_URL: |LaunchAuthURL : )(https?://[^\s]+)' , content )
109+ if matches :
110+ # Get the last URL and make sure it's a logout URL
111+ for url in reversed (matches ):
112+ if 'logout' in url or 'im-logged-out' in url :
113+ print (f"Found logout URL: { url } " )
114+ return url
115+ except Exception as e :
116+ print (f"Error reading log file { log_path } : { e } " )
117+ continue
118+
119+ print ("No logout URL found in Unity logs" )
120+ return None
121+
122+ def logout_with_controlled_browser ():
123+ """Handle logout using the controlled browser instance instead of letting Unity open its own browser."""
124+ print ("Starting controlled logout process..." )
125+
126+ # Set up Chrome WebDriver options to connect to the existing browser instance
127+ chrome_options = Options ()
128+ chrome_options .add_experimental_option ("debuggerAddress" , "localhost:9222" )
129+
130+ try :
131+ # Connect to the existing browser instance
132+ driver = webdriver .Chrome (options = chrome_options )
133+ print ("Connected to existing browser for logout" )
134+
135+ # Monitor Unity logs for logout URL
136+ print ("Monitoring Unity logs for logout URL..." )
137+ logout_url = None
138+ for attempt in range (15 ): # Try for 15 seconds (shorter timeout)
139+ logout_url = get_logout_url_from_unity_logs ()
140+ if logout_url :
141+ break
142+ time .sleep (1 )
143+
144+ if logout_url :
145+ print (f"Navigating controlled browser to logout URL: { logout_url } " )
146+ driver .get (logout_url )
147+
148+ # Wait for logout to complete (protocol is already configured, no dialogs expected)
149+ time .sleep (3 )
150+ print ("Logout completed in controlled browser" )
151+
152+ # Check final page
153+ current_url = driver .current_url
154+ print (f"Final logout URL: { current_url } " )
155+
156+ else :
157+ print ("Could not find logout URL in Unity logs - logout may complete without browser interaction" )
158+
159+ except Exception as e :
160+ print (f"Error during controlled logout: { e } " )
161+ print ("Logout may need to be handled by Unity directly" )
162+
163+ print ("Controlled logout process completed" )
164+
89165def handle_cached_authentication (driver ):
90166 """Handle scenarios where user is already authenticated (cached session)"""
91167 print ("Handling cached authentication scenario..." )
0 commit comments