Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8661: Always allow WebKit to load popup URLs before switching tabs #8683

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,16 @@ extension BrowserViewController: WKUIDelegate {
newTab.url = URL(string: "about:blank")

toolbarVisibilityViewModel.toolbarState = .expanded

// Wait until WebKit starts the request before selecting the new tab, otherwise the tab manager may
// restore it as if it was a dead tab.
var observation: NSKeyValueObservation?
observation = newTab.webView?.observe(\.url, changeHandler: { [weak self] webView, _ in
_ = observation // Silence write but not read warning
observation = nil
guard let self = self, let tab = self.tabManager[webView] else { return }
self.tabManager.selectTab(tab)
})

return newTab.webView
}
Expand Down
8 changes: 0 additions & 8 deletions Sources/Brave/Frontend/Browser/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,6 @@ class TabManager: NSObject {
@MainActor func addPopupForParentTab(_ parentTab: Tab, configuration: WKWebViewConfiguration) -> Tab {
let popup = Tab(configuration: configuration, id: UUID(), type: parentTab.type, tabGeneratorAPI: tabGeneratorAPI)
configureTab(popup, request: nil, afterTab: parentTab, flushToDisk: true, zombie: false, isPopup: true)

// Wait momentarily before selecting the new tab, otherwise the parent tab
// may be unable to set `window.location` on the popup immediately after
// calling `window.open("")`.
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
self.selectTab(popup)
}

return popup
}

Expand Down