Skip to content

Commit 136b371

Browse files
authored
Merge pull request #747 from Kilo-Org/mark/close-local-browser-properly
Close the local browser when used as fallback for remote
2 parents 96b2393 + d24cc88 commit 136b371

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.changeset/neat-cases-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
Close the browsertool properly when a remote browser is configured but a fallback local one is used

src/services/browser/BrowserSession.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class BrowserSession {
2121
private page?: Page
2222
private currentMousePosition?: string
2323
private lastConnectionAttempt?: number
24+
private isUsingRemoteBrowser: boolean = false // kilocode_change https://github.com/Kilo-Org/kilocode/pull/747
2425

2526
constructor(context: vscode.ExtensionContext) {
2627
this.context = context
@@ -70,6 +71,7 @@ export class BrowserSession {
7071
defaultViewport: this.getViewport(),
7172
// headless: false,
7273
})
74+
this.isUsingRemoteBrowser = false // kilocode_change https://github.com/Kilo-Org/kilocode/pull/747
7375
}
7476

7577
/**
@@ -86,6 +88,7 @@ export class BrowserSession {
8688
console.log(`Connected to remote browser at ${chromeHostUrl}`)
8789
this.context.globalState.update("cachedChromeHostUrl", chromeHostUrl)
8890
this.lastConnectionAttempt = Date.now()
91+
this.isUsingRemoteBrowser = true // kilocode_change https://github.com/Kilo-Org/kilocode/pull/747
8992

9093
return true
9194
} catch (error) {
@@ -192,8 +195,10 @@ export class BrowserSession {
192195
if (this.browser || this.page) {
193196
console.log("closing browser...")
194197

195-
const remoteBrowserEnabled = this.context.globalState.get("remoteBrowserEnabled") as boolean | undefined
196-
if (remoteBrowserEnabled && this.browser) {
198+
// kilocode_change start https://github.com/Kilo-Org/kilocode/pull/747
199+
if (this.isUsingRemoteBrowser && this.browser) {
200+
// kilocode_change end https://github.com/Kilo-Org/kilocode/pull/747
201+
197202
await this.browser.disconnect().catch(() => {})
198203
} else {
199204
await this.browser?.close().catch(() => {})
@@ -212,6 +217,7 @@ export class BrowserSession {
212217
this.browser = undefined
213218
this.page = undefined
214219
this.currentMousePosition = undefined
220+
this.isUsingRemoteBrowser = false // kilocode_change https://github.com/Kilo-Org/kilocode/pull/747
215221
}
216222

217223
async doAction(action: (page: Page) => Promise<void>): Promise<BrowserActionResult> {

0 commit comments

Comments
 (0)