From 7cade9727bf8d6b6aff4a995b73a3b917eee91ce Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Fri, 28 Jul 2023 10:15:27 -0400 Subject: [PATCH] Fix #7796, Fix #6966: Use `webViewDidClose` to handle `window.close` --- .../BrowserViewController+WKNavigationDelegate.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift index be1733c1d2a..cd29e99dd14 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift @@ -879,6 +879,12 @@ extension BrowserViewController: WKUIDelegate { return newTab.webView } + + public func webViewDidClose(_ webView: WKWebView) { + guard let tab = tabManager[webView] else { return } + tabManager.addTabToRecentlyClosed(tab) + tabManager.removeTab(tab) + } fileprivate func shouldDisplayJSAlertForWebView(_ webView: WKWebView) -> Bool { // Only display a JS Alert if we are selected and there isn't anything being shown