summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2016-09-01 22:45:14 +0200
committerFlorian Bruhin <git@the-compiler.org>2016-09-01 22:45:57 +0200
commit44d6db4f4518e6b1cd5a170caf822b9ff9b5a8be (patch)
tree7b80d5e04bd6339c96e438da7be74fc8c382b9bd
parentd8492fef613de7cf23bf0271732bae1d9f113451 (diff)
downloadqutebrowser-44d6db4f4518e6b1cd5a170caf822b9ff9b5a8be.tar.gz
qutebrowser-44d6db4f4518e6b1cd5a170caf822b9ff9b5a8be.zip
QtWebEngine: Fix crash with userscript + selection
Fixes #1878 Unfortunately it seems impossible to implement a test for this, as selection via javascript somehow doesn't trigger this.
-rw-r--r--doc/userscripts.asciidoc3
-rw-r--r--qutebrowser/browser/browsertab.py5
-rw-r--r--qutebrowser/browser/commands.py5
-rw-r--r--qutebrowser/browser/webengine/webenginetab.py2
4 files changed, 12 insertions, 3 deletions
diff --git a/doc/userscripts.asciidoc b/doc/userscripts.asciidoc
index e131bae9a..f25727ae6 100644
--- a/doc/userscripts.asciidoc
+++ b/doc/userscripts.asciidoc
@@ -42,7 +42,8 @@ In `command` mode:
- `QUTE_URL`: The current URL.
- `QUTE_TITLE`: The title of the current page.
- `QUTE_SELECTED_TEXT`: The text currently selected on the page.
-- `QUTE_SELECTED_HTML` The HTML currently selected on the page.
+- `QUTE_SELECTED_HTML` The HTML currently selected on the page (not supported
+ with QtWebEngine).
In `hints` mode:
diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py
index cfc5b385d..a704c325d 100644
--- a/qutebrowser/browser/browsertab.py
+++ b/qutebrowser/browser/browsertab.py
@@ -60,6 +60,11 @@ class WebTabError(Exception):
"""Base class for various errors."""
+class UnsupportedOperationError(WebTabError):
+
+ """Raised when an operation is not supported with the given backend."""
+
+
class TabData:
"""A simple namespace with a fixed set of attributes.
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
index 6b2bcc2ff..6ced51110 100644
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -1089,7 +1089,10 @@ class CommandDispatcher:
tab = self._tabbed_browser.currentWidget()
if tab is not None and tab.caret.has_selection():
env['QUTE_SELECTED_TEXT'] = tab.caret.selection()
- env['QUTE_SELECTED_HTML'] = tab.caret.selection(html=True)
+ try:
+ env['QUTE_SELECTED_HTML'] = tab.caret.selection(html=True)
+ except browsertab.UnsupportedOperationError:
+ pass
# FIXME:qtwebengine: If tab is None, run_async will fail!
diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py
index 9ff965600..41ddc6c80 100644
--- a/qutebrowser/browser/webengine/webenginetab.py
+++ b/qutebrowser/browser/webengine/webenginetab.py
@@ -171,7 +171,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
def selection(self, html=False):
if html:
- raise NotImplementedError
+ raise browsertab.UnsupportedOperationError
return self._widget.selectedText()
def follow_selected(self, *, tab=False):