@@ -846,6 +846,46 @@ def setup_browser_permissions():
846846 except Exception as e :
847847 print (f"Browser permission setup error: { e } " )
848848
849+
850+ def setup_autolaunch_protocol_policy ():
851+ """
852+ Configure Brave enterprise policy to allow external protocol launches without prompting.
853+
854+ Selenium cannot click the browser-level external protocol permission UI reliably.
855+ This policy avoids the prompt entirely by allowing `immutablerunner:` to auto-launch
856+ from the Passport origin.
857+
858+ Policy reference (Chromium/Edge naming):
859+ - AutoLaunchProtocolsFromOrigins: JSON array of { protocol, allowed_origins }
860+ - Registry path (Brave): HKCU\\ Software\\ Policies\\ BraveSoftware\\ Brave
861+ """
862+ print ("Setting up Brave AutoLaunchProtocolsFromOrigins policy..." )
863+
864+ # This must be REG_SZ containing JSON.
865+ # Protocol must be lowercase and WITHOUT ':' (e.g. "immutablerunner", not "immutablerunner:").
866+ policy_json = (
867+ '[{"protocol":"immutablerunner","allowed_origins":["https://auth.immutable.com"]}]'
868+ )
869+
870+ ps_script = f'''
871+ $key = "HKCU:\\ Software\\ Policies\\ BraveSoftware\\ Brave"
872+ if (!(Test-Path $key)) {{
873+ New-Item -Path $key -Force | Out-Null
874+ }}
875+ New-ItemProperty -Path $key -Name "AutoLaunchProtocolsFromOrigins" -PropertyType String -Value '{ policy_json } ' -Force | Out-Null
876+ Write-Host "Brave policy AutoLaunchProtocolsFromOrigins set."
877+ '''
878+
879+ try :
880+ result = subprocess .run (["powershell" , "-Command" , ps_script ], capture_output = True , text = True , timeout = 10 )
881+ if result .stdout :
882+ print (result .stdout .strip ())
883+ if result .stderr :
884+ # Non-fatal, but useful for debugging policy issues in CI.
885+ print (result .stderr .strip ())
886+ except Exception as e :
887+ print (f"Policy setup error: { e } " )
888+
849889def setup_protocol_association ():
850890 """Set up immutablerunner:// protocol association to avoid permission dialogs"""
851891 print ("Setting up protocol association for immutablerunner://..." )
@@ -919,6 +959,7 @@ def launch_browser():
919959 # Set up browser permissions and protocol association first
920960 setup_browser_permissions ()
921961 setup_protocol_association ()
962+ setup_autolaunch_protocol_policy ()
922963
923964 browser_paths = [
924965 r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe"
0 commit comments