Skip to content

Commit

Permalink
Ensure the JavaScript world ID is set for Brave Ads
Browse files Browse the repository at this point in the history
This fixes several upstream browser tests crashing on DCHECK-enabled
builds because of calls to dom_distiller::RunIsolatedJavaScript() being
run without the ID being previously set, with erros like this:

  [497557:497557:1221/135319.265636:FATAL:distiller_javascript_utils.cc(41)] Check failed: distiller_javascript_world_id != invalid_world_id.
  #0 0x7fd8cc5b7459 base::debug::CollectStackTrace()
  #1 0x7fd8cc4b12d3 base::debug::StackTrace::StackTrace()
  #2 0x7fd8cc4d3a34 logging::LogMessage::~LogMessage()
  #3 0x7fd8cc4d44ae logging::LogMessage::~LogMessage()
  #4 0x56550ee1de70 dom_distiller::RunIsolatedJavaScript()
  #5 0x56550fffc990 brave_ads::AdsTabHelper::RunIsolatedJavaScript()
  #6 0x7fd8c6332b3d content::WebContentsImpl::WebContentsObserverList::NotifyObservers<>()
  #7 0x7fd8c63531a9 content::WebContentsImpl::DocumentOnLoadCompleted()
  [...]
  #56 0x56550ccba27a _start
  Task trace:
  #0 0x7fd8c6c6ebee IPC::(anonymous namespace)::ChannelAssociatedGroupController::Accept()
  #1 0x7fd8cbce69df mojo::SimpleWatcher::Context::Notify()
  Crash keys:
    "ui_scheduler_async_stack" = "0x7FD8C6C6EBEE 0x7FD8CBCE69DF"
    "io_scheduler_async_stack" = "0x7FD8CBCE69DF 0x0"

  [1/1] TabStripBrowsertest.ShiftGroupLeft_OtherGroup (CRASHED)

This is necessary or all browser tests will crash when running on CI.
  • Loading branch information
mariospr committed Mar 14, 2022
1 parent 3ea5dfc commit 06ec699
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions browser/brave_ads/ads_tab_helper.cc
Expand Up @@ -10,6 +10,7 @@

#include "brave/browser/brave_ads/ads_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_isolated_world_ids.h"
#include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
#include "components/dom_distiller/content/browser/distiller_page_web_contents.h"
#include "components/sessions/content/session_tab_helper.h"
Expand Down Expand Up @@ -45,6 +46,11 @@ AdsTabHelper::AdsTabHelper(content::WebContents* web_contents)
OnBrowserSetLastActive(BrowserList::GetInstance()->GetLastActive());
#endif
OnVisibilityChanged(web_contents->GetVisibility());

// Set the JavaScript world ID if not assigned yet.
if (!dom_distiller::DistillerJavaScriptWorldIdIsSet())
dom_distiller::SetDistillerJavaScriptWorldId(
ISOLATED_WORLD_ID_BRAVE_INTERNAL);
}

AdsTabHelper::~AdsTabHelper() {
Expand Down

0 comments on commit 06ec699

Please sign in to comment.