Skip to content
Browse files
QtWebEngine: Add JS logging
  • Loading branch information
The-Compiler committed Jul 13, 2016
1 parent e35dfe7 commit 9c49900f9e98fc9f11115ce2bca864ece6899b59
@@ -25,6 +25,9 @@
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
# pylint: enable=no-name-in-module,import-error,useless-suppression

from qutebrowser.config import config
from qutebrowser.utils import log

class WebEngineView(QWebEngineView):

@@ -58,3 +61,19 @@ class WebEnginePage(QWebEnginePage):
def certificateError(self, error):
return super().certificateError(error)

def javaScriptConsoleMessage(self, level, msg, line, source):
"""Log javascript messages to qutebrowser's log."""
# FIXME:qtwebengine maybe unify this in the tab api somehow?
setting = config.get('general', 'log-javascript-console')
if setting == 'none':

level_to_logger = {
QWebEnginePage.WarningMessageLevel: log.js.warning,
QWebEnginePage.ErrorMessageLevel: log.js.error,
logstring = "[{}:{}] {}".format(source, line, msg)
logger = level_to_logger[level]
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<body onload="console.log('console.log works!')">
<p>This page logs a line via console.log</p>
@@ -2,6 +2,11 @@ Feature: Javascript stuff

Integration with javascript.

Scenario: Using console.log
When I set general -> log-javascript-console to debug
And I open data/javascript/consolelog.html
Then the javascript message "console.log works!" should be logged


Scenario: Closing a JS window twice (issue 906)

0 comments on commit 9c49900

Please sign in to comment.