Skip to content

Commit

Permalink
Log console messages explicitilly.
Browse files Browse the repository at this point in the history
Log js dialog execution. JS dialogs don't work due to upstream CEF bug:
chromiumembedded/cef#3818
https://magpcss.org/ceforum/viewtopic.php?f=6&t=20041
  • Loading branch information
cztomczak committed Nov 11, 2024
1 parent 0a04732 commit d940c58
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions cef/browser_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void BrowserWindow::SetIconFromSettings() {
bool BrowserWindow::SetFocus() {
// Calling SetFocus() on shellBrowser handle does not work.
if (cefBrowser_) {
LOGGER_INFO << "Focus browser, id=" << cefBrowser_->GetIdentifier();
cefBrowser_->GetHost()->SetFocus(true);
}
return true;
Expand Down
46 changes: 46 additions & 0 deletions cef/client_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,34 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> cefBrowser,
}
}

bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
cef_log_severity_t level,
const CefString& message,
const CefString& source,
int line)
{
std::string level_string = "UNKNOWN";
switch (level) {
case LOGSEVERITY_DEBUG:
level_string = "Debug";
break;
case LOGSEVERITY_INFO:
level_string = "Info";
break;
case LOGSEVERITY_WARNING:
level_string = "Warning";
break;
case LOGSEVERITY_ERROR:
level_string = "Error";
break;
case LOGSEVERITY_FATAL:
level_string = "Fatal";
break;
}
LOGGER_INFO << "JS Console: [" << level_string << "] " << message << "(" << source << ":" << line << ")";
return true;
}

// ----------------------------------------------------------------------------
// CefLifeSpanHandler methods
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -670,3 +698,21 @@ void ClientHandler::OnDownloadUpdated(
LOGGER_INFO << "Download was cancelled";
}
}

// ----------------------------------------------------------------------------
// CefDownloadHandler methods
// ----------------------------------------------------------------------------

bool ClientHandler::OnJSDialog(CefRefPtr<CefBrowser> browser,
const CefString& origin_url,
JSDialogType dialog_type,
const CefString& message_text,
const CefString& default_prompt_text,
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message)
{
// Use default implementation.
LOGGER_DEBUG << "JS dialog: " << message_text;
suppress_message = false;
return false;
}
20 changes: 19 additions & 1 deletion cef/client_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ClientHandler : public CefClient,
public CefDragHandler,
public CefRequestHandler,
public CefKeyboardHandler,
public CefDownloadHandler {
public CefDownloadHandler,
public CefJSDialogHandler {
public:
ClientHandler();
~ClientHandler();
Expand Down Expand Up @@ -49,6 +50,9 @@ class ClientHandler : public CefClient,
virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler() {
return this;
}
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() {
return this;
}
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
Expand All @@ -58,6 +62,11 @@ class ClientHandler : public CefClient,
// CefDisplayHandler methods:
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) override;
virtual bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
cef_log_severity_t level,
const CefString& message,
const CefString& source,
int line) override;

// CefLifeSpanHandler methods:
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
Expand Down Expand Up @@ -126,6 +135,15 @@ class ClientHandler : public CefClient,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback) override;

// CefJSDialogHandler methods:
virtual bool OnJSDialog(CefRefPtr<CefBrowser> browser,
const CefString& origin_url,
JSDialogType dialog_type,
const CefString& message_text,
const CefString& default_prompt_text,
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message) override;

private:
// Include the default reference counting implementation.
Expand Down

0 comments on commit d940c58

Please sign in to comment.