Skip to content

Commit

Permalink
Bugfix: Fix Youtube Internal links when 'Watching on Youtube' from Du…
Browse files Browse the repository at this point in the history
…ck Player (#3733)

Task/Issue URL: https://app.asana.com/0/1204099484721401/1208930843675395/f
Tech Design URL:
CC:

Description:
Fixes an issue causing Youtube internal links to open Duck Player
  • Loading branch information
afterxleep authored Dec 17, 2024
1 parent c55b610 commit 4baa50b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions DuckDuckGo/DuckPlayer/DuckPlayerNavigationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,16 @@ extension DuckPlayerNavigationHandler: DuckPlayerNavigationHandling {
return false
}

// Allow Youtube's internal navigation when DuckPlayer is enabled and user is watching on Youtube
// This is to prevent DuckPlayer from interfering with Youtube's internal navigation for search and settings
// https://app.asana.com/0/1204099484721401/1208930843675395/f
if let (destinationVideoID, _) = url.youtubeVideoParams,
let (originVideoID, _) = webView.url?.youtubeVideoParams,
destinationVideoID == originVideoID,
duckPlayerMode == .enabled {
return false
}

// Redirect to Duck Player if enabled
if url.isYoutubeWatch && duckPlayerMode == .enabled && !isDuckPlayerRedirect(url: url) {
redirectToDuckPlayerVideo(url: url, webView: webView)
Expand Down
20 changes: 20 additions & 0 deletions DuckDuckGoTests/YoutublePlayerNavigationHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,24 @@ class DuckPlayerNavigationHandlerTests: XCTestCase {
XCTAssertNil(tabNavigator.openedURL, "No new tabs should open")
}

@MainActor
func testHandleDelegateNavigation_YoutubeWatchURLWithDuckPlayerEnabledAndSameVideoNavigation_ReturnsFalse() async {
// Arrange
let youtubeURL = URL(string: "https://www.youtube.com/watch?v=abc123")!
let youtubeInternalURL = URL(string: "https://www.youtube.com/watch?v=abc123&settings")!
let request = URLRequest(url: youtubeURL)
let mockFrameInfo = MockFrameInfo(isMainFrame: true)
let navigationAction = MockNavigationAction(request: request, targetFrame: mockFrameInfo)
playerSettings.mode = .enabled
featureFlagger.enabledFeatures = [.duckPlayer, .duckPlayerOpenInNewTab]

mockWebView.setCurrentURL(youtubeInternalURL)

// Act
let shouldCancel = handler.handleDelegateNavigation(navigationAction: navigationAction, webView: mockWebView)

// Assert
XCTAssertFalse(shouldCancel, "Expected navigation NOT to be cancelled as it's Youtube Internal navigation")
}

}

0 comments on commit 4baa50b

Please sign in to comment.