diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index e33bd3049..2c94aa671 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -433,6 +433,15 @@ class AbstractElements: """ raise NotImplementedError + def find_id(self, elem_id, callback): + """Find the HTML element with the given ID async. + + Args: + callback: The callback to be called when the search finished. + elem_id: The ID to search for. + """ + raise NotImplementedError + def find_focused(self, callback): """Find the focused element on the page async. diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index bb70e2291..e916c4243 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -351,6 +351,11 @@ class WebEngineElements(browsertab.AbstractElements): js_cb = functools.partial(self._js_cb_multiple, callback) self._tab.run_js_async(js_code, js_cb) + def find_id(self, elem_id, callback): + js_code = javascript.assemble('document', 'getElementById', elem_id) + js_cb = functools.partial(self._js_cb_single, callback) + self._tab.run_js_async(js_code, js_cb) + def find_focused(self, callback): js_code = javascript.assemble('webelem', 'focus_element') js_cb = functools.partial(self._js_cb_single, callback) diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index 00b94bbb5..4e5eb10ee 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -512,6 +512,9 @@ class WebKitElements(browsertab.AbstractElements): callback(elems) + def find_id(self, elem_id, callback): + self.find_css('#' + elem_id, callback) + def find_focused(self, callback): frame = self._widget.page().currentFrame() if frame is None: