From 642d835d556ec416b8a20d7c712da0caba655866 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 6 Jan 2018 20:23:42 +0100 Subject: [PATCH] WebPage: Disable writing JavaScript warnings on stderr Can be enabled with QUPZILLA_ENABLE_JS_OUTPUT environment variable. --- src/lib/webengine/webpage.cpp | 27 +++++++++++++++++++++++++++ src/lib/webengine/webpage.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index ee2fd799c..8314f41ee 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -48,6 +48,8 @@ #include #endif +#include + #include #include #include @@ -63,6 +65,8 @@ QString WebPage::s_lastUploadLocation = QDir::homePath(); QUrl WebPage::s_lastUnsupportedUrl; QTime WebPage::s_lastUnsupportedUrlTime; +static const bool kEnableJsOutput = qEnvironmentVariableIsSet("QUPZILLA_ENABLE_JS_OUTPUT"); + WebPage::WebPage(QObject* parent) : QWebEnginePage(mApp->webProfile(), parent) , m_fileWatcher(0) @@ -562,6 +566,29 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) #endif } +void WebPage::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) +{ + if (!kEnableJsOutput) { + return; + } + + switch (level) { + case InfoMessageLevel: + std::cout << "[I] "; + break; + + case WarningMessageLevel: + std::cout << "[W] "; + break; + + case ErrorMessageLevel: + std::cout << "[E] "; + break; + } + + std::cout << qPrintable(sourceID) << ":" << lineNumber << " " << qPrintable(message); +} + void WebPage::setJavaScriptEnabled(bool enabled) { settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, enabled); diff --git a/src/lib/webengine/webpage.h b/src/lib/webengine/webpage.h index 7702f7539..32771e0c3 100644 --- a/src/lib/webengine/webpage.h +++ b/src/lib/webengine/webpage.h @@ -59,6 +59,7 @@ public: bool javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result) Q_DECL_OVERRIDE; bool javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE; void javaScriptAlert(const QUrl &securityOrigin, const QString &msg) Q_DECL_OVERRIDE; + void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) override; void setJavaScriptEnabled(bool enabled);