From 98a454a428c52013c2ba3bc722f091e76b45a779 Mon Sep 17 00:00:00 2001 From: Patric Schmitz Date: Sun, 29 Nov 2015 18:37:11 +0100 Subject: [PATCH 1/3] log-javascript-console -> [none, debug, info] --- qutebrowser/browser/webpage.py | 11 +++++++++-- qutebrowser/config/config.py | 4 +++- qutebrowser/config/configdata.py | 9 +++++++-- tests/integration/features/keyinput.feature | 12 ++++++------ tests/integration/features/misc.feature | 6 +++--- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/qutebrowser/browser/webpage.py b/qutebrowser/browser/webpage.py index 16460eaad..d9bb9fd41 100644 --- a/qutebrowser/browser/webpage.py +++ b/qutebrowser/browser/webpage.py @@ -503,8 +503,15 @@ class BrowserPage(QWebPage): def javaScriptConsoleMessage(self, msg, line, source): """Override javaScriptConsoleMessage to use debug log.""" - if config.get('general', 'log-javascript-console'): - log.js.debug("[{}:{}] {}".format(source, line, msg)) + log_javascript_console = config.get('general', + 'log-javascript-console') + logstring = "[{}:{}] {}".format(source, line, msg) + logmap = { + 'debug': log.js.debug, + 'info': log.js.info, + 'none': lambda arg: None + } + logmap[log_javascript_console](logstring) def chooseFile(self, _frame, suggested_file): """Override QWebPage's chooseFile to be able to chose a file to upload. diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index aea69494b..88ca89e5d 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -356,7 +356,9 @@ class ConfigManager(QObject): ('tabs', 'position'): _transform_position, ('ui', 'downloads-position'): _transform_position, ('ui', 'remove-finished-downloads'): - _get_value_transformer({'false': '-1', 'true': '1000'}) + _get_value_transformer({'false': '-1', 'true': '1000'}), + ('general', 'log-javascript-console'): + _get_value_transformer({'false': 'none', 'true': 'debug'}), } changed = pyqtSignal(str, str) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 387d4225b..7d184f781 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -229,8 +229,13 @@ def data(readonly=False): "launched."), ('log-javascript-console', - SettingValue(typ.Bool(), 'false'), - "Whether to log javascript console messages."), + SettingValue(typ.String( + valid_values=typ.ValidValues( + ('none', 'Not displayed'), + ('debug', 'Display in debug mode'), + ('info', 'Display always') + )), 'debug'), + "How to log javascript console messages."), ('save-session', SettingValue(typ.Bool(), 'false'), diff --git a/tests/integration/features/keyinput.feature b/tests/integration/features/keyinput.feature index 42454e7dd..1536249e2 100644 --- a/tests/integration/features/keyinput.feature +++ b/tests/integration/features/keyinput.feature @@ -67,7 +67,7 @@ Feature: Keyboard input Scenario: Forwarding all keys When I open data/keyinput/log.html - And I set general -> log-javascript-console to true + And I set general -> log-javascript-console to info And I set input -> forward-unbound-keys to all And I press the key "q" And I press the key "" @@ -80,7 +80,7 @@ Feature: Keyboard input Scenario: Forwarding special keys When I open data/keyinput/log.html - And I set general -> log-javascript-console to true + And I set general -> log-javascript-console to info And I set input -> forward-unbound-keys to auto And I press the key "x" And I press the key "" @@ -93,7 +93,7 @@ Feature: Keyboard input Scenario: Forwarding no keys When I open data/keyinput/log.html - And I set general -> log-javascript-console to true + And I set general -> log-javascript-console to info And I set input -> forward-unbound-keys to none And I press the key "" # @@ -107,7 +107,7 @@ Feature: Keyboard input Then the error "Could not parse 'blub': Got unknown key." should be shown Scenario: :fake-key sending key to the website - When I set general -> log-javascript-console to true + When I set general -> log-javascript-console to info And I open data/keyinput/log.html And I run :fake-key x Then the javascript message "key press: 88" should be logged @@ -125,14 +125,14 @@ Feature: Keyboard input Then the error "No focused webview!" should be shown Scenario: :fake-key sending special key to the website - When I set general -> log-javascript-console to true + When I set general -> log-javascript-console to info And I open data/keyinput/log.html And I run :fake-key Then the javascript message "key press: 27" should be logged And the javascript message "key release: 27" should be logged Scenario: :fake-key sending keychain to the website - When I set general -> log-javascript-console to true + When I set general -> log-javascript-console to info And I open data/keyinput/log.html And I run :fake-key xy Then the javascript message "key press: 88" should be logged diff --git a/tests/integration/features/misc.feature b/tests/integration/features/misc.feature index 07b2ff77c..b47c09759 100644 --- a/tests/integration/features/misc.feature +++ b/tests/integration/features/misc.feature @@ -50,19 +50,19 @@ Feature: Various utility commands. ## :jseval Scenario: :jseval - When I set general -> log-javascript-console to true + When I set general -> log-javascript-console to info And I run :jseval console.log("Hello from JS!"); And I wait for "[:0] Hello from JS!" in the log Then the message "No output or error" should be shown Scenario: :jseval without logging - When I set general -> log-javascript-console to false + When I set general -> log-javascript-console to none And I run :jseval console.log("Hello from JS!"); Then the message "No output or error" should be shown And "[:0] Hello from JS!" should not be logged Scenario: :jseval with --quiet - When I set general -> log-javascript-console to true + When I set general -> log-javascript-console to info And I run :jseval --quiet console.log("Hello from JS!"); And I wait for "[:0] Hello from JS!" in the log Then "No output or error" should not be logged From a8b808819ac46830cd1e010b643f5af93a7d55b6 Mon Sep 17 00:00:00 2001 From: Patric Schmitz Date: Sun, 29 Nov 2015 19:24:09 +0100 Subject: [PATCH 2/3] update log-javascript-console option documentation --- qutebrowser/config/configdata.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 7d184f781..915f3ae4d 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -231,9 +231,9 @@ def data(readonly=False): ('log-javascript-console', SettingValue(typ.String( valid_values=typ.ValidValues( - ('none', 'Not displayed'), - ('debug', 'Display in debug mode'), - ('info', 'Display always') + ('none', "Don't log messages."), + ('debug', "Log messages with debug level."), + ('info', "Log messages with info level.") )), 'debug'), "How to log javascript console messages."), From 6ad1d37eb539fde920a32da180c60a6e62530345 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 30 Nov 2015 08:08:52 +0100 Subject: [PATCH 3/3] Regenerate docs. --- doc/help/settings.asciidoc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index f0262b5c1..bb521816a 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -20,7 +20,7 @@ |<>|Enable workarounds for broken sites. |<>|Default encoding to use for websites. |<>|How to open links in an existing instance if a new one is launched. -|<>|Whether to log javascript console messages. +|<>|How to log javascript console messages. |<>|Whether to always save the open pages. |<>|The name of the session to save by default, or empty for the last loaded session. |<>|The URL segments where `:navigate increment/decrement` will search for a number. @@ -439,14 +439,15 @@ Default: +pass:[tab]+ [[general-log-javascript-console]] === log-javascript-console -Whether to log javascript console messages. +How to log javascript console messages. Valid values: - * +true+ - * +false+ + * +none+: Don't log messages. + * +debug+: Log messages with debug level. + * +info+: Log messages with info level. -Default: +pass:[false]+ +Default: +pass:[debug]+ [[general-save-session]] === save-session