Compare commits

...

1 Commits

Author SHA1 Message Date
Samuel Attard
72e8bbffc2 feat: expose frame and stack trace in the console-message event 2023-06-23 13:20:19 -07:00
4 changed files with 64 additions and 14 deletions

View File

@@ -935,10 +935,17 @@ Emitted when a `<webview>` has been attached to this web contents.
Returns:
* `event` Event
* `level` Integer - The log level, from 0 to 3. In order it matches `verbose`, `info`, `warning` and `error`.
* `message` string - The actual console message
* `line` Integer - The line number of the source that triggered this console message
* `sourceId` string
* `_` never - deprecated parameter
* `__` never - deprecated parameter
* `___` never - deprecated parameter
* `____` never - deprecated parameter
* `details` Object
* `frame` WebFrameMain - The frame that logged the message
* `level` Integer - The log level, from 0 to 3. In order it matches `verbose`, `info`, `warning` and `error`.
* `message` string - The actual console message
* `lineNumber` Integer - The line number of the source that triggered this console message
* `sourceId` String - Url the log message came from, can be the empty string
* `untrustedStackTrace` String | undefined - Undefined in most cases, optionally present for exceptions that are logged
Emitted when the associated window logs a console message.

View File

@@ -107,6 +107,7 @@
#include "shell/common/api/electron_bindings.h"
#include "shell/common/color_util.h"
#include "shell/common/electron_constants.h"
#include "shell/common/gin_converters/absl_converter.h"
#include "shell/common/gin_converters/base_converter.h"
#include "shell/common/gin_converters/blink_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
@@ -1106,14 +1107,25 @@ void WebContents::Close(absl::optional<gin_helper::Dictionary> options) {
}
}
bool WebContents::DidAddMessageToConsole(
content::WebContents* source,
void WebContents::OnDidAddMessageToConsole(
content::RenderFrameHost* source_frame,
blink::mojom::ConsoleMessageLevel level,
const std::u16string& message,
int32_t line_no,
const std::u16string& source_id) {
return Emit("console-message", static_cast<int32_t>(level), message, line_no,
source_id);
const std::u16string& source_id,
const absl::optional<std::u16string>& untrusted_stack_trace) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
details.SetGetter("frame", source_frame);
details.Set("level", static_cast<int32_t>(level));
details.Set("message", message);
details.Set("lineNumber", line_no);
details.Set("sourceId", source_id);
details.Set("untrustedStackTrace", untrusted_stack_trace);
Emit("console-message", static_cast<int32_t>(level), message, line_no,
source_id, details);
}
void WebContents::OnCreateWindow(

View File

@@ -491,11 +491,6 @@ class WebContents : public ExclusiveAccessContext,
#endif
// content::WebContentsDelegate:
bool DidAddMessageToConsole(content::WebContents* source,
blink::mojom::ConsoleMessageLevel level,
const std::u16string& message,
int32_t line_no,
const std::u16string& source_id) override;
bool IsWebContentsCreationOverridden(
content::SiteInstance* source_site_instance,
content::mojom::WindowContainerType window_container_type,
@@ -634,6 +629,13 @@ class WebContents : public ExclusiveAccessContext,
content::RenderWidgetHost* render_widget_host) override;
void OnWebContentsLostFocus(
content::RenderWidgetHost* render_widget_host) override;
void OnDidAddMessageToConsole(
content::RenderFrameHost* source_frame,
blink::mojom::ConsoleMessageLevel log_level,
const std::u16string& message,
int32_t line_no,
const std::u16string& source_id,
const absl::optional<std::u16string>& untrusted_stack_trace) override;
// InspectableWebContentsDelegate:
void DevToolsReloadPage() override;

View File

@@ -0,0 +1,29 @@
// Copyright (c) 2022 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_ABSL_CONVERTER_H_
#define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_ABSL_CONVERTER_H_
#include "gin/converter.h"
namespace ui {
class Accelerator;
}
namespace gin {
template <typename T>
struct Converter<absl::optional<T>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
absl::optional<T> status) {
if (status) {
return gin::ConvertToV8(isolate, *status);
}
return v8::Undefined(isolate);
}
};
} // namespace gin
#endif // ELECTRON_SHELL_COMMON_GIN_CONVERTERS_ABSL_CONVERTER_H_