Add caret browsing debug logging

This commit is contained in:
Florian Bruhin 2024-03-27 16:55:18 +01:00
parent 481542844d
commit 7a969a2d54
4 changed files with 28 additions and 4 deletions

View File

@ -292,6 +292,8 @@ class WebEngineCaret(browsertab.AbstractCaret):
flags = set()
if utils.is_windows:
flags.add('windows')
if 'caret' in objects.debug_flags:
flags.add('debug')
return list(flags)
@pyqtSlot(usertypes.KeyMode)

View File

@ -739,6 +739,12 @@ window._qutebrowser.caret = (function() {
*/
CaretBrowsing.isWindows = null;
/**
* Whether we should log debug outputs.
* @type {boolean}
*/
CaretBrowsing.isDebug = null;
/**
* The id returned by window.setInterval for our stopAnimation function, so
* we can cancel it when we call stopAnimation again.
@ -1150,6 +1156,8 @@ window._qutebrowser.caret = (function() {
action = "extend";
}
CaretBrowsing.debug(`(move) ${action} ${count} ${granularity} ${direction}, selection ${CaretBrowsing.selectionState}`);
for (let i = 0; i < count; i++) {
if (CaretBrowsing.selectionState === CaretBrowsing.SelectionState.LINE) {
CaretBrowsing.updateLineSelection(direction, granularity);
@ -1180,6 +1188,8 @@ window._qutebrowser.caret = (function() {
if (CaretBrowsing.selectionState !== CaretBrowsing.SelectionState.NONE) {
action = "extend";
}
CaretBrowsing.debug(`(moveToBlock) ${action} paragraph ${paragraph}, boundary ${boundary}, count ${count}, selection ${CaretBrowsing.selectionState}`);
for (let i = 0; i < count; i++) {
window.
getSelection().
@ -1196,6 +1206,7 @@ window._qutebrowser.caret = (function() {
};
CaretBrowsing.toggle = function(value) {
CaretBrowsing.debug(`(toggle) enabled ${CaretBrowsing.isEnabled}, force ${CaretBrowsing.forceEnabled}`);
if (CaretBrowsing.forceEnabled) {
CaretBrowsing.recreateCaretElement();
return;
@ -1231,6 +1242,7 @@ window._qutebrowser.caret = (function() {
* is enabled and whether this window / iframe has focus.
*/
CaretBrowsing.updateIsCaretVisible = function() {
CaretBrowsing.debug(`(updateIsCaretVisible) isEnabled ${CaretBrowsing.isEnabled}, isWindowFocused ${CaretBrowsing.isWindowFocused}, isCaretVisible ${CaretBrowsing.isCaretVisible}, caretElement ${CaretBrowsing.caretElement}`);
CaretBrowsing.isCaretVisible =
(CaretBrowsing.isEnabled && CaretBrowsing.isWindowFocused);
if (CaretBrowsing.isCaretVisible && !CaretBrowsing.caretElement) {
@ -1274,6 +1286,12 @@ window._qutebrowser.caret = (function() {
}
};
CaretBrowsing.debug = (text) => {
if (CaretBrowsing.isDebug) {
console.debug(`caret: ${text}`);
}
}
CaretBrowsing.init = function() {
CaretBrowsing.isWindowFocused = document.hasFocus();
@ -1313,6 +1331,7 @@ window._qutebrowser.caret = (function() {
funcs.setFlags = (flags) => {
CaretBrowsing.isWindows = flags.includes("windows");
CaretBrowsing.isDebug = flags.includes("debug");
};
funcs.disableCaret = () => {

View File

@ -171,12 +171,13 @@ def debug_flag_error(flag):
avoid-chromium-init: Enable `--version` without initializing Chromium.
werror: Turn Python warnings into errors.
test-notification-service: Use the testing libnotify service.
caret: Enable debug logging for caret.js.
"""
valid_flags = ['debug-exit', 'pdb-postmortem', 'no-sql-history',
'no-scroll-filtering', 'log-requests', 'log-cookies',
'log-scroll-pos', 'log-sensitive-keys', 'stack', 'chromium',
'wait-renderer-process', 'avoid-chromium-init', 'werror',
'test-notification-service', 'log-qt-events']
'test-notification-service', 'log-qt-events', 'caret']
if flag in valid_flags:
return flag

View File

@ -405,9 +405,11 @@ class QuteProc(testprocess.Process):
backend = 'webengine' if self.request.config.webengine else 'webkit'
args = ['--debug', '--no-err-windows', '--temp-basedir',
'--json-logging', '--loglevel', 'vdebug',
'--backend', backend, '--debug-flag', 'no-sql-history',
'--debug-flag', 'werror', '--debug-flag',
'test-notification-service',
'--backend', backend,
'--debug-flag', 'no-sql-history',
'--debug-flag', 'werror',
'--debug-flag', 'test-notification-service',
'--debug-flag', 'caret',
'--qt-flag', 'disable-features=PaintHoldingCrossOrigin']
if self.request.config.webengine and testutils.disable_seccomp_bpf_sandbox():