Add a webelem logger

This commit is contained in:
Florian Bruhin 2016-09-07 11:51:23 +02:00
parent c3b80c6b5b
commit 0ff98f568c
4 changed files with 14 additions and 12 deletions

View File

@ -214,14 +214,14 @@ class AbstractWebElement(collections.abc.MutableMapping):
def _is_editable_object(self): def _is_editable_object(self):
"""Check if an object-element is editable.""" """Check if an object-element is editable."""
if 'type' not in self: if 'type' not in self:
log.webview.debug("<object> without type clicked...") log.webelem.debug("<object> without type clicked...")
return False return False
objtype = self['type'].lower() objtype = self['type'].lower()
if objtype.startswith('application/') or 'classid' in self: if objtype.startswith('application/') or 'classid' in self:
# Let's hope flash/java stuff has an application/* mimetype OR # Let's hope flash/java stuff has an application/* mimetype OR
# at least a classid attribute. Oh, and let's hope images/... # at least a classid attribute. Oh, and let's hope images/...
# DON'T have a classid attribute. HTML sucks. # DON'T have a classid attribute. HTML sucks.
log.webview.debug("<object type='{}'> clicked.".format(objtype)) log.webelem.debug("<object type='{}'> clicked.".format(objtype))
return config.get('input', 'insert-mode-on-plugins') return config.get('input', 'insert-mode-on-plugins')
else: else:
# Image/Audio/... # Image/Audio/...
@ -270,7 +270,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
True if we should switch to insert mode, False otherwise. True if we should switch to insert mode, False otherwise.
""" """
roles = ('combobox', 'textbox') roles = ('combobox', 'textbox')
log.misc.debug("Checking if element is editable: {}".format( log.webelem.debug("Checking if element is editable: {}".format(
repr(self))) repr(self)))
tag = self.tag_name() tag = self.tag_name()
if self.is_content_editable() and self.is_writable(): if self.is_content_editable() and self.is_writable():
@ -361,8 +361,8 @@ class AbstractWebElement(collections.abc.MutableMapping):
pos = self._mouse_pos() pos = self._mouse_pos()
log.hints.debug("Sending fake click to {!r} at position {} with " log.webelem.debug("Sending fake click to {!r} at position {} with "
"target {}".format(self, pos, click_target)) "target {}".format(self, pos, click_target))
if click_target in [usertypes.ClickTarget.tab, if click_target in [usertypes.ClickTarget.tab,
usertypes.ClickTarget.tab_bg, usertypes.ClickTarget.tab_bg,

View File

@ -111,7 +111,7 @@ class WebEngineElement(webelem.AbstractWebElement):
def insert_text(self, text): def insert_text(self, text):
if not self.is_editable(strict=True): if not self.is_editable(strict=True):
raise webelem.Error("Element is not editable!") raise webelem.Error("Element is not editable!")
log.misc.debug("Inserting text into element {!r}".format(self)) log.webelem.debug("Inserting text into element {!r}".format(self))
js_code = javascript.assemble('webelem', 'insert_text', self._id, text) js_code = javascript.assemble('webelem', 'insert_text', self._id, text)
self._tab.run_js_async(js_code) self._tab.run_js_async(js_code)
@ -159,7 +159,7 @@ class WebEngineElement(webelem.AbstractWebElement):
# rect.translate(frame.geometry().topLeft()) # rect.translate(frame.geometry().topLeft())
# frame = frame.parentFrame() # frame = frame.parentFrame()
return rect return rect
log.webview.debug("Couldn't find rectangle for {!r} ({})".format( log.webelem.debug("Couldn't find rectangle for {!r} ({})".format(
self, rects)) self, rects))
return QRect() return QRect()

View File

@ -126,10 +126,10 @@ class WebKitElement(webelem.AbstractWebElement):
def set_text(self, text, *, use_js=False): def set_text(self, text, *, use_js=False):
self._check_vanished() self._check_vanished()
if self.is_content_editable() or not use_js: if self.is_content_editable() or not use_js:
log.misc.debug("Filling {!r} via set_text.".format(self)) log.webelem.debug("Filling {!r} via set_text.".format(self))
self._elem.setPlainText(text) self._elem.setPlainText(text)
else: else:
log.misc.debug("Filling {!r} via javascript.".format(self)) log.webelem.debug("Filling {!r} via javascript.".format(self))
text = javascript.string_escape(text) text = javascript.string_escape(text)
self._elem.evaluateJavaScript("this.value='{}'".format(text)) self._elem.evaluateJavaScript("this.value='{}'".format(text))
@ -137,7 +137,7 @@ class WebKitElement(webelem.AbstractWebElement):
self._check_vanished() self._check_vanished()
if not self.is_editable(strict=True): if not self.is_editable(strict=True):
raise webelem.Error("Element is not editable!") raise webelem.Error("Element is not editable!")
log.misc.debug("Inserting text into element {!r}".format(self)) log.webelem.debug("Inserting text into element {!r}".format(self))
self._elem.evaluateJavaScript(""" self._elem.evaluateJavaScript("""
var text = "{}"; var text = "{}";
var event = document.createEvent("TextEvent"); var event = document.createEvent("TextEvent");
@ -163,7 +163,7 @@ class WebKitElement(webelem.AbstractWebElement):
return None return None
text = utils.compact_text(self._elem.toOuterXml(), 500) text = utils.compact_text(self._elem.toOuterXml(), 500)
log.hints.vdebug("Client rectangles of element '{}': {}".format( log.webelem.vdebug("Client rectangles of element '{}': {}".format(
text, rects)) text, rects))
for i in range(int(rects.get("length", 0))): for i in range(int(rects.get("length", 0))):

View File

@ -93,7 +93,8 @@ LOGGER_NAMES = [
'mouse', 'procs', 'hints', 'keyboard', 'mouse', 'procs', 'hints', 'keyboard',
'commands', 'signals', 'downloads', 'commands', 'signals', 'downloads',
'js', 'qt', 'rfc6266', 'ipc', 'shlexer', 'js', 'qt', 'rfc6266', 'ipc', 'shlexer',
'save', 'message', 'config', 'sessions' 'save', 'message', 'config', 'sessions',
'webelem'
] ]
@ -137,6 +138,7 @@ save = logging.getLogger('save')
message = logging.getLogger('message') message = logging.getLogger('message')
config = logging.getLogger('config') config = logging.getLogger('config')
sessions = logging.getLogger('sessions') sessions = logging.getLogger('sessions')
webelem = logging.getLogger('webelem')
ram_handler = None ram_handler = None