Skip to content

Commit

Permalink
fix(duckplayer): prevent new tab creation on target=_blank links
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Apr 16, 2024
1 parent 2f0828e commit f14e449
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ extension DuckPlayerTabExtension: YoutubeOverlayUserScriptDelegate {
extension DuckPlayerTabExtension: NewWindowPolicyDecisionMaker {

func decideNewWindowPolicy(for navigationAction: WKNavigationAction) -> NavigationDecision? {
// if a link was clicked inside duckplayer (like a recommendation)
// and has target=_blank - then we want to prevent a new tab
// opening, and just load it inside the current one instead
if navigationAction.targetFrame == nil,
navigationAction.safeSourceFrame?.webView?.url?.isDuckPlayer == true,
navigationAction.request.url?.isYoutubeVideoRecommendation == true,
let webView, let url = navigationAction.request.url {
webView.load(URLRequest(url: url))
return .cancel
}

if let shouldSelectNextNewTab {
defer {
self.shouldSelectNextNewTab = nil
Expand Down

0 comments on commit f14e449

Please sign in to comment.