@@ -108,23 +108,37 @@ pub async fn browser_auth_flow(gateway_endpoint: &str) -> Result<String> {
108108 gateway_endpoint. to_string ( ) ,
109109 ) ) ;
110110
111+ // Allow suppressing the browser popup via environment variable (useful for
112+ // CI, e2e tests, and headless environments).
113+ let no_browser = std:: env:: var ( "OPENSHELL_NO_BROWSER" )
114+ . map ( |v| v == "1" || v. eq_ignore_ascii_case ( "true" ) )
115+ . unwrap_or ( false ) ;
116+
111117 // Prompt the user before opening the browser.
112118 eprintln ! ( " Confirmation code: {code}" ) ;
113119 eprintln ! ( " Verify this code matches your browser before clicking Connect." ) ;
114120 eprintln ! ( ) ;
115- eprint ! ( "Press Enter to open the browser for authentication..." ) ;
116- std:: io:: stderr ( ) . flush ( ) . ok ( ) ;
117- let mut _input = String :: new ( ) ;
118- std:: io:: stdin ( ) . read_line ( & mut _input) . ok ( ) ;
119-
120- if let Err ( e) = open_browser ( & auth_url) {
121- debug ! ( error = %e, "failed to open browser" ) ;
122- eprintln ! ( "Could not open browser automatically." ) ;
121+
122+ if no_browser {
123+ eprintln ! ( "Browser opening suppressed (OPENSHELL_NO_BROWSER is set)." ) ;
123124 eprintln ! ( "Open this URL in your browser:" ) ;
124125 eprintln ! ( " {auth_url}" ) ;
125126 eprintln ! ( ) ;
126127 } else {
127- eprintln ! ( "Browser opened." ) ;
128+ eprint ! ( "Press Enter to open the browser for authentication..." ) ;
129+ std:: io:: stderr ( ) . flush ( ) . ok ( ) ;
130+ let mut _input = String :: new ( ) ;
131+ std:: io:: stdin ( ) . read_line ( & mut _input) . ok ( ) ;
132+
133+ if let Err ( e) = open_browser ( & auth_url) {
134+ debug ! ( error = %e, "failed to open browser" ) ;
135+ eprintln ! ( "Could not open browser automatically." ) ;
136+ eprintln ! ( "Open this URL in your browser:" ) ;
137+ eprintln ! ( " {auth_url}" ) ;
138+ eprintln ! ( ) ;
139+ } else {
140+ eprintln ! ( "Browser opened." ) ;
141+ }
128142 }
129143
130144 // Wait for the callback or timeout.
0 commit comments