@@ -30,7 +30,7 @@ import { McpHub } from "../../services/mcp/McpHub"
3030import { McpServerManager } from "../../services/mcp/McpServerManager"
3131import { ShadowCheckpointService } from "../../services/checkpoints/ShadowCheckpointService"
3232import { BrowserSession } from "../../services/browser/BrowserSession"
33- import { discoverChromeInstances } from "../../services/browser/browserDiscovery"
33+ import { discoverChromeHostUrl , tryChromeHostUrl } from "../../services/browser/browserDiscovery"
3434import { fileExistsAtPath } from "../../utils/fs"
3535import { playSound , setSoundEnabled , setSoundVolume } from "../../utils/sound"
3636import { singleCompletionHandler } from "../../utils/single-completion-handler"
@@ -1279,74 +1279,17 @@ export class ClineProvider implements vscode.WebviewViewProvider {
12791279 await this . postStateToWebview ( )
12801280 break
12811281 case "testBrowserConnection" :
1282- try {
1283- const browserSession = new BrowserSession ( this . context )
1284- // If no text is provided, try auto-discovery
1285- if ( ! message . text ) {
1286- try {
1287- const discoveredHost = await discoverChromeInstances ( )
1288- if ( discoveredHost ) {
1289- // Test the connection to the discovered host
1290- const result = await browserSession . testConnection ( discoveredHost )
1291- // Send the result back to the webview
1292- await this . postMessageToWebview ( {
1293- type : "browserConnectionResult" ,
1294- success : result . success ,
1295- text : `Auto-discovered and tested connection to Chrome at ${ discoveredHost } : ${ result . message } ` ,
1296- values : { endpoint : result . endpoint } ,
1297- } )
1298- } else {
1299- await this . postMessageToWebview ( {
1300- type : "browserConnectionResult" ,
1301- success : false ,
1302- text : "No Chrome instances found on the network. Make sure Chrome is running with remote debugging enabled (--remote-debugging-port=9222)." ,
1303- } )
1304- }
1305- } catch ( error ) {
1306- await this . postMessageToWebview ( {
1307- type : "browserConnectionResult" ,
1308- success : false ,
1309- text : `Error during auto-discovery: ${ error instanceof Error ? error . message : String ( error ) } ` ,
1310- } )
1311- }
1312- } else {
1313- // Test the provided URL
1314- const result = await browserSession . testConnection ( message . text )
1315-
1316- // Send the result back to the webview
1317- await this . postMessageToWebview ( {
1318- type : "browserConnectionResult" ,
1319- success : result . success ,
1320- text : result . message ,
1321- values : { endpoint : result . endpoint } ,
1322- } )
1323- }
1324- } catch ( error ) {
1325- await this . postMessageToWebview ( {
1326- type : "browserConnectionResult" ,
1327- success : false ,
1328- text : `Error testing connection: ${ error instanceof Error ? error . message : String ( error ) } ` ,
1329- } )
1330- }
1331- break
1332- case "discoverBrowser" :
1333- try {
1334- const discoveredHost = await discoverChromeInstances ( )
1335-
1336- if ( discoveredHost ) {
1337- // Don't update the remoteBrowserHost state when auto-discovering
1338- // This way we don't override the user's preference
1339-
1340- // Test the connection to get the endpoint
1341- const browserSession = new BrowserSession ( this . context )
1342- const result = await browserSession . testConnection ( discoveredHost )
1343-
1282+ // If no text is provided, try auto-discovery
1283+ if ( ! message . text ) {
1284+ // Use testBrowserConnection for auto-discovery
1285+ const chromeHostUrl = await discoverChromeHostUrl ( )
1286+ if ( chromeHostUrl ) {
13441287 // Send the result back to the webview
13451288 await this . postMessageToWebview ( {
13461289 type : "browserConnectionResult" ,
1347- success : true ,
1348- text : `Successfully discovered and connected to Chrome at ${ discoveredHost } ` ,
1349- values : { endpoint : result . endpoint } ,
1290+ success : ! ! chromeHostUrl ,
1291+ text : `Auto- discovered and tested connection to Chrome: ${ chromeHostUrl } ` ,
1292+ values : { endpoint : chromeHostUrl } ,
13501293 } )
13511294 } else {
13521295 await this . postMessageToWebview ( {
@@ -1355,11 +1298,17 @@ export class ClineProvider implements vscode.WebviewViewProvider {
13551298 text : "No Chrome instances found on the network. Make sure Chrome is running with remote debugging enabled (--remote-debugging-port=9222)." ,
13561299 } )
13571300 }
1358- } catch ( error ) {
1301+ } else {
1302+ // Test the provided URL
1303+ const customHostUrl = message . text
1304+ const hostIsValid = await tryChromeHostUrl ( message . text )
1305+ // Send the result back to the webview
13591306 await this . postMessageToWebview ( {
13601307 type : "browserConnectionResult" ,
1361- success : false ,
1362- text : `Error discovering browser: ${ error instanceof Error ? error . message : String ( error ) } ` ,
1308+ success : hostIsValid ,
1309+ text : hostIsValid
1310+ ? `Successfully connected to Chrome: ${ customHostUrl } `
1311+ : "Failed to connect to Chrome" ,
13631312 } )
13641313 }
13651314 break
@@ -2393,6 +2342,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
23932342 screenshotQuality : screenshotQuality ?? 75 ,
23942343 remoteBrowserHost,
23952344 remoteBrowserEnabled : remoteBrowserEnabled ?? false ,
2345+ cachedChromeHostUrl : ( await this . getGlobalState ( "cachedChromeHostUrl" ) ) as string | undefined ,
23962346 preferredLanguage : preferredLanguage ?? "English" ,
23972347 writeDelayMs : writeDelayMs ?? 1000 ,
23982348 terminalOutputLineLimit : terminalOutputLineLimit ?? 500 ,
@@ -2548,6 +2498,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
25482498 screenshotQuality : stateValues . screenshotQuality ?? 75 ,
25492499 remoteBrowserHost : stateValues . remoteBrowserHost ,
25502500 remoteBrowserEnabled : stateValues . remoteBrowserEnabled ?? false ,
2501+ cachedChromeHostUrl : stateValues . cachedChromeHostUrl as string | undefined ,
25512502 fuzzyMatchThreshold : stateValues . fuzzyMatchThreshold ?? 1.0 ,
25522503 writeDelayMs : stateValues . writeDelayMs ?? 1000 ,
25532504 terminalOutputLineLimit : stateValues . terminalOutputLineLimit ?? 500 ,
0 commit comments