Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable ReportingObserver and make noop #24726

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class ReportingObserverTest : public InProcessBrowserTest {
}
};

IN_PROC_BROWSER_TEST_F(ReportingObserverTest, IsDisabled) {
IN_PROC_BROWSER_TEST_F(ReportingObserverTest, IsNoop) {
GURL url = embedded_test_server()->GetURL(kReportingObserver);
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();

EXPECT_EQ(true, EvalJs(contents, "isReportingObserverDisabled();"));
EXPECT_EQ(true, EvalJs(contents, "isReportingObserverNoop();"));
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "third_party/blink/renderer/core/frame/reporting_observer.h"

#define QueueReport QueueReport_Unused
#include "src/third_party/blink/renderer/core/frame/reporting_observer.cc"
#undef QueueReport

namespace blink {

void ReportingObserver::QueueReport(Report* report) {
ShivanKaul marked this conversation as resolved.
Show resolved Hide resolved
// Don't add reports. We previously used to disable ReportingObserver in
// Brave, but for webcompat reasons, we now just no-op it. This makes
// takeRecords() always return an empty list.
return;
ShivanKaul marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace blink
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORTING_OBSERVER_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORTING_OBSERVER_H_

#define QueueReport \
QueueReport_Unused(Report* report); \
void QueueReport

#include "src/third_party/blink/renderer/core/frame/reporting_observer.h" // IWYU pragma: export

#undef QueueReport

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORTING_OBSERVER_H_

This file was deleted.

This file was deleted.

22 changes: 16 additions & 6 deletions test/data/reporting_observer.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<script>
function isReportingObserverDisabled() {
function isReportingObserverNoop() {
try {
new ReportingObserver(function(reports, observer) {
return false;
}, {});
} catch (err) {
return true;
const observer = new ReportingObserver(() => {},
{ types: ['deprecation'], buffered: true }
);
observer.observe();
const xhr = new XMLHttpRequest();
// false makes it synchronous, which is deprecated.
xhr.open('GET', '/', false);
xhr.send(null);
const reports = observer.takeRecords();
console.log("Reports:", reports);
// Even though we made a synchronous request, we should not have any reports.
return reports.length === 0;
} catch (error) {
console.error("Error occurred:", error);
return false;
}
}
</script>
Loading