From 1788465fe11afad5b61cb9b07763d56e35561376 Mon Sep 17 00:00:00 2001 From: sw3205933776 <3205933776@qq.com> Date: Thu, 11 Sep 2025 18:37:55 +0800 Subject: [PATCH 1/2] fix: browser not working due to no active page available (#328) --- electron/main/webview.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/electron/main/webview.ts b/electron/main/webview.ts index 20816fd1b..4ac0a7738 100644 --- a/electron/main/webview.ts +++ b/electron/main/webview.ts @@ -120,10 +120,12 @@ export class WebViewManager { const activeSize = this.getActiveWebview().length const allSize = Array.from(this.webViews.values()).length if (allSize - activeSize <= 3) { - const newId = Array.from(this.webViews.keys()).length + 2 + const newId = (Math.max(0, ...Array.from(this.webViews.keys()).map(Number)) || 0) + 2 this.createWebview(newId.toString(), 'about:blank?use=0') this.createWebview((newId + 1).toString(), 'about:blank?use=0') this.createWebview((newId + 2).toString(), 'about:blank?use=0') + this.createWebview((newId + 3).toString(), 'about:blank?use=0') + this.createWebview((newId + 4).toString(), 'about:blank?use=0') } // setTimeout(() => { From f4a90e8c69934103c016d554a5d094170d694f08 Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Mon, 15 Sep 2025 16:51:50 +0800 Subject: [PATCH 2/2] enhance: PR 335 browser not working due to no active page available --- electron/main/webview.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/electron/main/webview.ts b/electron/main/webview.ts index 4ac0a7738..123d464d2 100644 --- a/electron/main/webview.ts +++ b/electron/main/webview.ts @@ -112,20 +112,23 @@ export class WebViewManager { } console.log(`Webview ${id} navigated to: ${navigationUrl}`) if (webViewInfo.isActive && webViewInfo.isShow && navigationUrl !== 'about:blank?use=0' && navigationUrl !== 'about:blank') { - console.log("did-navigate", id, url) - this.win?.webContents.send("url-updated", url); + console.log("did-navigate", id, navigationUrl) + this.win?.webContents.send("url-updated", navigationUrl); return } webViewInfo.view.setBounds({ x: -1919, y: -1079, width: 1920, height: 1080 }) const activeSize = this.getActiveWebview().length const allSize = Array.from(this.webViews.values()).length if (allSize - activeSize <= 3) { - const newId = (Math.max(0, ...Array.from(this.webViews.keys()).map(Number)) || 0) + 2 - this.createWebview(newId.toString(), 'about:blank?use=0') - this.createWebview((newId + 1).toString(), 'about:blank?use=0') - this.createWebview((newId + 2).toString(), 'about:blank?use=0') - this.createWebview((newId + 3).toString(), 'about:blank?use=0') - this.createWebview((newId + 4).toString(), 'about:blank?use=0') + const existingKeys = Array.from(this.webViews.keys()).map(Number).filter(n => !isNaN(n)) + const maxId = existingKeys.length > 0 ? Math.max(...existingKeys) : 0 + const startId = maxId + 1 + + // Create webviews sequentially to avoid race conditions + for (let i = 0; i < 3; i++) { + const nextId = (startId + i).toString() + this.createWebview(nextId, 'about:blank?use=0') + } } // setTimeout(() => { @@ -244,8 +247,12 @@ export class WebViewManager { } } - public distroy() { - // TODO: Destroy all webviews + public destroy() { + // Destroy all webviews + Array.from(this.webViews.keys()).forEach(id => { + this.destroyWebview(id) + }) + this.webViews.clear() } }