@@ -2826,17 +2826,56 @@ end tell
28262826 _eventSubscriptions.remove ('Page.frameStoppedLoading' );
28272827 }
28282828
2829+ /// Auto-click the "Allow remote debugging?" dialog that Chrome 146 shows
2830+ /// when an external app connects via the consent port.
2831+ ///
2832+ /// Chrome renders the dialog as a native AXSheet inside the front window.
2833+ /// The Allow button has description="Allow" (not name="Allow"), so we
2834+ /// search by description via the macOS Accessibility API using AppleScript.
2835+ Future <void > _autoAllowChromeConsentDialog () async {
2836+ const script = '''
2837+ tell application "System Events"
2838+ tell process "Google Chrome"
2839+ repeat 15 times
2840+ try
2841+ set frontWin to front window
2842+ set theSheet to sheet 1 of frontWin
2843+ set allElems to entire contents of theSheet
2844+ repeat with e in allElems
2845+ try
2846+ if role of e is "AXButton" and description of e is "Allow" then
2847+ click e
2848+ return "ok"
2849+ end if
2850+ end try
2851+ end repeat
2852+ end try
2853+ delay 0.5
2854+ end repeat
2855+ return "not_found"
2856+ end tell
2857+ end tell
2858+ ''' ;
2859+ try {
2860+ await Process .run ('osascript' , ['-e' , script]);
2861+ } catch (_) {}
2862+ }
2863+
28292864 /// For Chrome 146+'s consent-based port (no HTTP endpoints):
28302865 /// Connect via WebSocket to the browser-level CDP endpoint, send
28312866 /// Target.getTargets, find the best matching target, and return its WS URL.
28322867 ///
2833- /// Chrome shows "Allow remote debugging?" dialog on first connection.
2834- /// We wait up to [timeout] seconds for the user to click Allow .
2868+ /// Chrome shows "Allow remote debugging?" dialog — auto-clicked via
2869+ /// macOS Accessibility API so the user never has to manually confirm .
28352870 Future <String ?> _discoverTargetViaConsentPort ({
28362871 Duration timeout = const Duration (seconds: 30 ),
28372872 }) async {
28382873 final wsUrl = 'ws://127.0.0.1:$_port /devtools/browser/${_generateUuid ()}' ;
28392874 WebSocket ? ws;
2875+ // Auto-click the Allow dialog in parallel with the WebSocket connection.
2876+ // Chrome shows the dialog as soon as the upgrade request arrives; the
2877+ // WebSocket handshake completes only after the user (or us) clicks Allow.
2878+ unawaited (_autoAllowChromeConsentDialog ());
28402879 try {
28412880 ws = await _connectWebSocketNoOrigin (wsUrl, timeout: timeout);
28422881 } catch (_) {
0 commit comments