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 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 837b55f4c..727145e0a 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..915f3ae4d 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', "Don't log messages."), + ('debug', "Log messages with debug level."), + ('info', "Log messages with info level.") + )), '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