diff --git a/browser/brave_ads/tabs/ads_tab_helper.cc b/browser/brave_ads/tabs/ads_tab_helper.cc index a92b56bcfb22..4d8eddd912cd 100644 --- a/browser/brave_ads/tabs/ads_tab_helper.cc +++ b/browser/brave_ads/tabs/ads_tab_helper.cc @@ -18,6 +18,7 @@ #include "components/sessions/content/session_tab_helper.h" #include "components/sessions/core/session_id.h" #include "content/public/browser/navigation_handle.h" +#include "content/public/browser/page.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" #include "net/http/http_response_headers.h" @@ -327,6 +328,18 @@ void AdsTabHelper::MaybeNotifyTabdidClose() { } } +void AdsTabHelper::PrimaryPageChanged(content::Page& page) { + if (!ads_service_) { + // No-op if the ads service is unavailable. + return; + } + + // Calling `ResetNavigationState` from `DidStartNavigation` causes an issue + // where `NotifyTab[Text|Html]ContentDidChange` is not triggered when a user + // enables aggressive tracker and ad blocking, then proceeds to the page. + ResetNavigationState(); +} + void AdsTabHelper::DidStartNavigation( content::NavigationHandle* navigation_handle) { if (!ads_service_ || !navigation_handle->IsInPrimaryMainFrame()) { diff --git a/browser/brave_ads/tabs/ads_tab_helper.h b/browser/brave_ads/tabs/ads_tab_helper.h index 2fe92dd4d988..7309996e9cf3 100644 --- a/browser/brave_ads/tabs/ads_tab_helper.h +++ b/browser/brave_ads/tabs/ads_tab_helper.h @@ -95,6 +95,7 @@ class AdsTabHelper : public content::WebContentsObserver, void MaybeNotifyTabdidClose(); // content::WebContentsObserver: + void PrimaryPageChanged(content::Page& page) override; void DidStartNavigation( content::NavigationHandle* navigation_handle) override; void DidFinishNavigation(