diff --git a/DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift b/DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift index a419a42dbe..92d5a63573 100644 --- a/DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift +++ b/DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift @@ -307,8 +307,7 @@ extension DuckPlayerTabExtension: NavigationResponder { // “Watch in YouTube” selected // when currently displayed content is the Duck Player and loading a YouTube URL, don‘t override it - if navigationAction.targetFrame?.url.isDuckPlayer == true, - navigationAction.targetFrame?.url.youtubeVideoID == videoID { + if didUserSelectWatchInYoutubeFromDuckPlayer(navigationAction, preferences: preferences, videoID: videoID) { PixelKit.fire(GeneralPixel.duckPlayerWatchOnYoutube) return .next @@ -344,6 +343,11 @@ extension DuckPlayerTabExtension: NavigationResponder { return .next } + private func didUserSelectWatchInYoutubeFromDuckPlayer(_ navigationAction: NavigationAction, preferences: DuckPlayerPreferences, videoID: String) -> Bool { + let url = preferences.duckPlayerOpenInNewTab ? navigationAction.sourceFrame.url : navigationAction.targetFrame?.url + return url?.isDuckPlayer == true && url?.youtubeVideoID == videoID + } + func didCommit(_ navigation: Navigation) { guard duckPlayer.isAvailable, duckPlayer.mode != .disabled else { return