mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
feat: suppress devtools console logging (#49359)
* feat: suppress devtools console logging Co-authored-by: clavin <clavin@electronjs.org> * Emit messages as-is in testing builds Co-authored-by: clavin <clavin@electronjs.org> * Promote `DCHECK_IS_ON()` to preprocessor check Co-authored-by: clavin <clavin@electronjs.org> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org>
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "base/base64.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "base/dcheck_is_on.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/metrics/histogram.h"
|
||||
#include "base/strings/pattern.h"
|
||||
@@ -957,6 +958,35 @@ bool InspectableWebContents::HandleKeyboardEvent(
|
||||
return !delegate || delegate->HandleKeyboardEvent(source, event);
|
||||
}
|
||||
|
||||
bool InspectableWebContents::DidAddMessageToConsole(
|
||||
content::WebContents* source,
|
||||
blink::mojom::ConsoleMessageLevel log_level,
|
||||
const std::u16string& message,
|
||||
int32_t line_no,
|
||||
const std::u16string& source_id) {
|
||||
// Suppress Chromium's default logging of DevTools frontend console messages
|
||||
// into native logs for the managed DevTools WebContents. Can be overridden by
|
||||
// enabling verbose logging.
|
||||
if (source == managed_devtools_web_contents_.get()) {
|
||||
#if DCHECK_IS_ON()
|
||||
// In debug/testing builds, let logging through.
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (VLOG_IS_ON(1)) {
|
||||
// Match Chromium's `content::LogConsoleMessage()` output format, but emit
|
||||
// it as a verbose log.
|
||||
logging::LogMessage("CONSOLE", line_no, logging::LOGGING_VERBOSE).stream()
|
||||
<< "\"" << message << "\", source: " << source_id << " (" << line_no
|
||||
<< ")";
|
||||
}
|
||||
|
||||
return true; // Suppress the default logging.
|
||||
}
|
||||
|
||||
return false; // Allow the default logging.
|
||||
}
|
||||
|
||||
void InspectableWebContents::CloseContents(content::WebContents* source) {
|
||||
// This is where the devtools closes itself (by clicking the x button).
|
||||
CloseDevTools();
|
||||
|
||||
@@ -221,6 +221,11 @@ class InspectableWebContents
|
||||
// content::WebContentsDelegate:
|
||||
bool HandleKeyboardEvent(content::WebContents*,
|
||||
const input::NativeWebKeyboardEvent&) override;
|
||||
bool DidAddMessageToConsole(content::WebContents* source,
|
||||
blink::mojom::ConsoleMessageLevel log_level,
|
||||
const std::u16string& message,
|
||||
int32_t line_no,
|
||||
const std::u16string& source_id) override;
|
||||
void CloseContents(content::WebContents* source) override;
|
||||
std::unique_ptr<content::EyeDropper> OpenEyeDropper(
|
||||
content::RenderFrameHost* frame,
|
||||
|
||||
Reference in New Issue
Block a user