fix(cli): update F12 behavior to only open drawer if browser fails (#18829)

This commit is contained in:
Sandy Tao
2026-02-11 09:45:43 -08:00
committed by GitHub
parent eb9223b6a4
commit b19b026f30
3 changed files with 42 additions and 15 deletions

View File

@@ -212,14 +212,24 @@ async function startDevToolsServerImpl(config: Config): Promise<string> {
/**
* Handles the F12 key toggle for the DevTools panel.
* Starts the DevTools server, attempts to open the browser,
* and always calls the toggle callback regardless of the outcome.
* Starts the DevTools server, attempts to open the browser.
* If the panel is already open, it closes it.
* If the panel is closed:
* - Attempts to open the browser.
* - If browser opening is successful, the panel remains closed.
* - If browser opening fails or is not possible, the panel is opened.
*/
export async function toggleDevToolsPanel(
config: Config,
isOpen: boolean,
toggle: () => void,
setOpen: () => void,
): Promise<void> {
if (isOpen) {
toggle();
return;
}
try {
const { openBrowserSecurely, shouldLaunchBrowser } = await import(
'@google/gemini-cli-core'
@@ -228,11 +238,14 @@ export async function toggleDevToolsPanel(
if (shouldLaunchBrowser()) {
try {
await openBrowserSecurely(url);
// Browser opened successfully, don't open drawer.
return;
} catch (e) {
debugLogger.warn('Failed to open browser securely:', e);
}
}
toggle();
// If we can't launch browser or it failed, open drawer.
setOpen();
} catch (e) {
setOpen();
debugLogger.error('Failed to start DevTools server:', e);