@@ -660,10 +660,27 @@ def login():
660660
661661 # The "open external protocol" prompt is typically browser UI (not DOM),
662662 # so 0 buttons on /checking is expected. Try:
663+ # - wait for /checking to transition (some runs redirect after a few seconds)
663664 # - wait briefly for Unity success (maybe protocol already fired)
664665 # - click the browser-level prompt via UIAutomation
665666 # - wait again for Unity success
666667 if "auth.immutable.com/checking" in current_url_lower :
668+ # Monitor for URL transitions for ~30 seconds.
669+ for _ in range (15 ):
670+ time .sleep (2 )
671+ try :
672+ current = driver .current_url or ""
673+ print (f"/checking monitor - current URL: { current } " )
674+ lower = current .lower ()
675+ if "newtab" in lower or "about:blank" in lower :
676+ print ("Detected newtab/about:blank; assuming external protocol launch was attempted." )
677+ wait_for_authentication_success_in_unity_logs (timeout_seconds = 75 )
678+ return
679+ if "auth.immutable.com/checking" not in lower :
680+ break
681+ except Exception :
682+ pass
683+
667684 if wait_for_authentication_success_in_unity_logs (timeout_seconds = 10 ):
668685 return
669686
@@ -810,14 +827,11 @@ def bring_sample_app_to_foreground():
810827 subprocess .run (command , check = True )
811828 time .sleep (10 )
812829
813- def setup_browser_permissions ():
814- """Set up browser permissions to allow auth.immutable.com to open external applications"""
830+ def setup_browser_permissions (user_data_dir : str ):
831+ """Set up browser profile permissions to allow auth.immutable.com to open external applications. """
815832 print ("Setting up browser permissions for auth.immutable.com..." )
816-
817- # Create a browser preferences file to pre-allow the domain
818- user_data_dir = "C:\\ temp\\ brave_debug"
819- if not os .path .exists (user_data_dir ):
820- os .makedirs (user_data_dir , exist_ok = True )
833+ print (f"Using browser profile dir: { user_data_dir } " )
834+ os .makedirs (user_data_dir , exist_ok = True )
821835
822836 # Create preferences file that allows auth.immutable.com to open external apps
823837 preferences = {
@@ -864,16 +878,27 @@ def setup_autolaunch_protocol_policy():
864878 # This must be REG_SZ containing JSON.
865879 # Protocol must be lowercase and WITHOUT ':' (e.g. "immutablerunner", not "immutablerunner:").
866880 policy_json = (
867- '[{"protocol":"immutablerunner","allowed_origins":["https://auth.immutable.com"]}]'
881+ '[{"protocol":"immutablerunner","allowed_origins":["https://auth.immutable.com","https://auth.immutable.com:443" ]}]'
868882 )
869883
870884 ps_script = f'''
871- $key = "HKCU:\\ Software\\ Policies\\ BraveSoftware\\ Brave"
872- if (!(Test-Path $key)) {{
873- New-Item -Path $key -Force | Out-Null
885+ $json = '{ policy_json } '
886+ $paths = @(
887+ "HKCU:\\ Software\\ Policies\\ BraveSoftware\\ Brave",
888+ "HKLM:\\ Software\\ Policies\\ BraveSoftware\\ Brave"
889+ )
890+
891+ foreach ($key in $paths) {{
892+ try {{
893+ if (!(Test-Path $key)) {{
894+ New-Item -Path $key -Force | Out-Null
895+ }}
896+ New-ItemProperty -Path $key -Name "AutoLaunchProtocolsFromOrigins" -PropertyType String -Value $json -Force | Out-Null
897+ Write-Host "Brave policy AutoLaunchProtocolsFromOrigins set at $key."
898+ }} catch {{
899+ Write-Host "Failed to set policy at $key: $($_.Exception.Message)"
900+ }}
874901 }}
875- New-ItemProperty -Path $key -Name "AutoLaunchProtocolsFromOrigins" -PropertyType String -Value '{ policy_json } ' -Force | Out-Null
876- Write-Host "Brave policy AutoLaunchProtocolsFromOrigins set."
877902 '''
878903
879904 try :
@@ -956,11 +981,6 @@ def setup_protocol_association():
956981def launch_browser ():
957982 print ("Starting Brave..." )
958983
959- # Set up browser permissions and protocol association first
960- setup_browser_permissions ()
961- setup_protocol_association ()
962- setup_autolaunch_protocol_policy ()
963-
964984 browser_paths = [
965985 r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe"
966986 ]
@@ -978,6 +998,11 @@ def launch_browser():
978998 # Create a temporary directory for browser data to ensure clean state
979999 import tempfile
9801000 temp_user_data = tempfile .mkdtemp (prefix = 'brave_test_' )
1001+
1002+ # IMPORTANT: apply permissions to the SAME profile we launch with.
1003+ setup_browser_permissions (user_data_dir = temp_user_data )
1004+ setup_protocol_association ()
1005+ setup_autolaunch_protocol_policy ()
9811006
9821007 # Launch Brave with CI-friendly flags to handle protocol dialogs automatically
9831008 browser_args = [
0 commit comments