Skip to content

Commit 2a80fed

Browse files
Garothhugelung
andauthored
proto migration for testBrowserConnection.ts (RooCodeInc#2922)
* proto migration for testBrowserConnection.ts * format fix --------- Co-authored-by: Andrei Edell <[email protected]>
1 parent 450583c commit 2a80fed

File tree

10 files changed

+713
-74
lines changed

10 files changed

+713
-74
lines changed

proto/browser.proto

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ import "common.proto";
66

77
service BrowserService {
88
rpc getBrowserConnectionInfo(EmptyRequest) returns (BrowserConnectionInfo);
9+
rpc testBrowserConnection(StringRequest) returns (BrowserConnection);
910
}
1011

1112
message BrowserConnectionInfo {
1213
bool is_connected = 1;
1314
bool is_remote = 2;
14-
string host = 3; // Optional, may be empty
15+
optional string host = 3;
16+
}
17+
18+
message BrowserConnection {
19+
bool success = 1;
20+
string message = 2;
21+
optional string endpoint = 3;
1522
}

proto/common.proto

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,30 @@ message EmptyRequest {
1111

1212
message Empty {
1313
}
14+
15+
message StringRequest {
16+
Metadata metadata = 1;
17+
string value = 2;
18+
}
19+
20+
message String {
21+
string value = 1;
22+
}
23+
24+
message Int64Request {
25+
Metadata metadata = 1;
26+
int64 value = 2;
27+
}
28+
29+
message Int64 {
30+
int64 value = 1;
31+
}
32+
33+
message BytesRequest {
34+
Metadata metadata = 1;
35+
bytes value = 2;
36+
}
37+
38+
message Bytes {
39+
bytes value = 1;
40+
}

src/core/controller/browser/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// Import all method implementations
55
import { registerMethod } from "./index"
66
import { getBrowserConnectionInfo } from "./getBrowserConnectionInfo"
7+
import { testBrowserConnection } from "./testBrowserConnection"
78

89
// Register all browser service methods
910
export function registerAllMethods(): void {
1011
// Register each method with the registry
1112
registerMethod("getBrowserConnectionInfo", getBrowserConnectionInfo)
13+
registerMethod("testBrowserConnection", testBrowserConnection)
1214
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { BrowserConnection } from "../../../shared/proto/browser"
2+
import { StringRequest } from "../../../shared/proto/common"
3+
import { Controller } from "../index"
4+
import { getAllExtensionState } from "../../storage/state"
5+
import { BrowserSession } from "../../../services/browser/BrowserSession"
6+
import { discoverChromeInstances } from "../../../services/browser/BrowserDiscovery"
7+
8+
/**
9+
* Test connection to a browser instance
10+
* @param controller The controller instance
11+
* @param request The request message
12+
* @returns The browser connection result
13+
*/
14+
export async function testBrowserConnection(controller: Controller, request: StringRequest): Promise<BrowserConnection> {
15+
try {
16+
const { browserSettings } = await getAllExtensionState(controller.context)
17+
const browserSession = new BrowserSession(controller.context, browserSettings)
18+
const text = request.value || ""
19+
20+
// If no text is provided, try auto-discovery
21+
if (!text) {
22+
try {
23+
const discoveredHost = await discoverChromeInstances()
24+
if (discoveredHost) {
25+
// Test the connection to the discovered host
26+
const result = await browserSession.testConnection(discoveredHost)
27+
return {
28+
success: result.success,
29+
message: `Auto-discovered and tested connection to Chrome at ${discoveredHost}: ${result.message}`,
30+
endpoint: result.endpoint || "",
31+
}
32+
} else {
33+
return {
34+
success: false,
35+
message:
36+
"No Chrome instances found on the network. Make sure Chrome is running with remote debugging enabled (--remote-debugging-port=9222).",
37+
endpoint: "",
38+
}
39+
}
40+
} catch (error) {
41+
return {
42+
success: false,
43+
message: `Error during auto-discovery: ${error instanceof Error ? error.message : String(error)}`,
44+
endpoint: "",
45+
}
46+
}
47+
} else {
48+
// Test the provided URL
49+
const result = await browserSession.testConnection(text)
50+
return {
51+
success: result.success,
52+
message: result.message,
53+
endpoint: result.endpoint || "",
54+
}
55+
}
56+
} catch (error) {
57+
return {
58+
success: false,
59+
message: `Error testing connection: ${error instanceof Error ? error.message : String(error)}`,
60+
endpoint: "",
61+
}
62+
}
63+
}

src/core/controller/index.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -311,58 +311,6 @@ export class Controller {
311311
await this.postStateToWebview()
312312
}
313313
break
314-
case "testBrowserConnection":
315-
try {
316-
const { browserSettings } = await getAllExtensionState(this.context)
317-
const browserSession = new BrowserSession(this.context, browserSettings)
318-
// If no text is provided, try auto-discovery
319-
if (!message.text) {
320-
try {
321-
const discoveredHost = await discoverChromeInstances()
322-
if (discoveredHost) {
323-
// Test the connection to the discovered host
324-
const result = await browserSession.testConnection(discoveredHost)
325-
// Send the result back to the webview
326-
await this.postMessageToWebview({
327-
type: "browserConnectionResult",
328-
success: result.success,
329-
text: `Auto-discovered and tested connection to Chrome at ${discoveredHost}: ${result.message}`,
330-
endpoint: result.endpoint,
331-
})
332-
} else {
333-
await this.postMessageToWebview({
334-
type: "browserConnectionResult",
335-
success: false,
336-
text: "No Chrome instances found on the network. Make sure Chrome is running with remote debugging enabled (--remote-debugging-port=9222).",
337-
})
338-
}
339-
} catch (error) {
340-
await this.postMessageToWebview({
341-
type: "browserConnectionResult",
342-
success: false,
343-
text: `Error during auto-discovery: ${error instanceof Error ? error.message : String(error)}`,
344-
})
345-
}
346-
} else {
347-
// Test the provided URL
348-
const result = await browserSession.testConnection(message.text)
349-
350-
// Send the result back to the webview
351-
await this.postMessageToWebview({
352-
type: "browserConnectionResult",
353-
success: result.success,
354-
text: result.message,
355-
endpoint: result.endpoint,
356-
})
357-
}
358-
} catch (error) {
359-
await this.postMessageToWebview({
360-
type: "browserConnectionResult",
361-
success: false,
362-
text: `Error testing connection: ${error instanceof Error ? error.message : String(error)}`,
363-
})
364-
}
365-
break
366314
case "discoverBrowser":
367315
try {
368316
const discoveredHost = await discoverChromeInstances()

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export interface WebviewMessage {
4040
| "autoApprovalSettings"
4141
| "browserSettings"
4242
| "discoverBrowser"
43-
| "testBrowserConnection"
44-
| "browserConnectionResult"
4543
| "browserRelaunchResult"
4644
| "togglePlanActMode"
4745
| "checkpointDiff"

src/shared/proto/browser.ts

Lines changed: 113 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)