diff --git a/electron/lib/navigation.js b/electron/lib/navigation.js index ec7343249..4bf266e04 100644 --- a/electron/lib/navigation.js +++ b/electron/lib/navigation.js @@ -123,17 +123,17 @@ function navigateTopLevel(webContents, direction) { return false } if (direction === 'back') { - if (!webContents.canGoBack()) { + if (!webContents.navigationHistory.canGoBack()) { return false } - webContents.goBack() + webContents.navigationHistory.goBack() return true } if (direction === 'forward') { - if (!webContents.canGoForward()) { + if (!webContents.navigationHistory.canGoForward()) { return false } - webContents.goForward() + webContents.navigationHistory.goForward() return true } return false diff --git a/electron/lib/web-tab-manager.js b/electron/lib/web-tab-manager.js index 7e0dfa08b..1015abc34 100644 --- a/electron/lib/web-tab-manager.js +++ b/electron/lib/web-tab-manager.js @@ -1642,6 +1642,23 @@ function registerIPC() { event.returnValue = "ok" }) + /** + * 内置浏览器 - 延迟发送导航状态 + */ + function notifyNavigationState(item) { + setTimeout(() => { + const wd = webTabWindows.get(item.view.webTabWindowId) + if (wd && wd.window) { + utils.onDispatchEvent(wd.window.webContents, { + event: 'navigation-state', + id: item.id, + canGoBack: item.view.webContents.navigationHistory.canGoBack(), + canGoForward: item.view.webContents.navigationHistory.canGoForward() + }).then(_ => { }) + } + }, 100) + } + /** * 内置浏览器 - 后退 */ @@ -1652,19 +1669,9 @@ function registerIPC() { event.returnValue = "ok" return } - if (item.view.webContents.canGoBack()) { - item.view.webContents.goBack() - setTimeout(() => { - const wd = webTabWindows.get(item.view.webTabWindowId) - if (wd && wd.window) { - utils.onDispatchEvent(wd.window.webContents, { - event: 'navigation-state', - id: item.id, - canGoBack: item.view.webContents.canGoBack(), - canGoForward: item.view.webContents.canGoForward() - }).then(_ => { }) - } - }, 100) + if (item.view.webContents.navigationHistory.canGoBack()) { + item.view.webContents.navigationHistory.goBack() + notifyNavigationState(item) } event.returnValue = "ok" }) @@ -1679,19 +1686,9 @@ function registerIPC() { event.returnValue = "ok" return } - if (item.view.webContents.canGoForward()) { - item.view.webContents.goForward() - setTimeout(() => { - const wd = webTabWindows.get(item.view.webTabWindowId) - if (wd && wd.window) { - utils.onDispatchEvent(wd.window.webContents, { - event: 'navigation-state', - id: item.id, - canGoBack: item.view.webContents.canGoBack(), - canGoForward: item.view.webContents.canGoForward() - }).then(_ => { }) - } - }, 100) + if (item.view.webContents.navigationHistory.canGoForward()) { + item.view.webContents.navigationHistory.goForward() + notifyNavigationState(item) } event.returnValue = "ok" }) @@ -1735,8 +1732,8 @@ function registerIPC() { return } - const canGoBack = item.view.webContents.canGoBack() - const canGoForward = item.view.webContents.canGoForward() + const canGoBack = item.view.webContents.navigationHistory.canGoBack() + const canGoForward = item.view.webContents.navigationHistory.canGoForward() const wd = webTabWindows.get(item.view.webTabWindowId) if (wd && wd.window) {