diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 5f5f37a46..91cff0af3 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -51,6 +51,8 @@ Changed one), which allows scripts like OneeChan to work. - Rapid hinting is now supported with the `yank` and `yank-primary` targets, copying newline-separated links. +- QtWebEngine: On Qt 5.11, the developer tools (inspector) can now be used + securely and without requiring the `--enable-webengine-inspector` option. Removed ~~~~~~~ diff --git a/doc/qutebrowser.1.asciidoc b/doc/qutebrowser.1.asciidoc index 1d264dc10..89407611a 100644 --- a/doc/qutebrowser.1.asciidoc +++ b/doc/qutebrowser.1.asciidoc @@ -60,7 +60,7 @@ show it. Which backend to use. *--enable-webengine-inspector*:: - Enable the web inspector for QtWebEngine. Note that this is a SECURITY RISK and you should not visit untrusted websites with the inspector turned on. See https://bugreports.qt.io/browse/QTBUG-50725 for more details. + Enable the web inspector for QtWebEngine. Note that this is a SECURITY RISK and you should not visit untrusted websites with the inspector turned on. See https://bugreports.qt.io/browse/QTBUG-50725 for more details. This is not needed anymore since Qt 5.11 where the inspector is always enabled and secure. === debug arguments *-l* '{critical,error,warning,info,debug,vdebug}', *--loglevel* '{critical,error,warning,info,debug,vdebug}':: diff --git a/qutebrowser/browser/webengine/webengineinspector.py b/qutebrowser/browser/webengine/webengineinspector.py index 0145ad634..22f948439 100644 --- a/qutebrowser/browser/webengine/webengineinspector.py +++ b/qutebrowser/browser/webengine/webengineinspector.py @@ -39,8 +39,8 @@ class WebEngineInspector(inspector.AbstractWebInspector): settings.setAttribute(QWebEngineSettings.JavascriptEnabled, True) self._set_widget(view) - def inspect(self, _page): - """Set up the inspector.""" + def _inspect_old(self): + """Set up the inspector for Qt < 5.11.""" try: port = int(os.environ['QTWEBENGINE_REMOTE_DEBUGGING']) except KeyError: @@ -49,4 +49,14 @@ class WebEngineInspector(inspector.AbstractWebInspector): "'qutebrowser --help' for details.") url = QUrl('http://localhost:{}/'.format(port)) self._widget.load(url) + + def _inspect_new(self, page): + """Set up the inspector for Qt >= 5.11.""" + self._widget.page().setInspectedPage(page) + + def inspect(self, page): + try: + self._inspect_new(page) + except AttributeError: + self._inspect_old() self.show() diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py index e3efc780c..3a5e138d3 100644 --- a/qutebrowser/browser/webengine/webenginesettings.py +++ b/qutebrowser/browser/webengine/webenginesettings.py @@ -27,7 +27,8 @@ Module attributes: import os from PyQt5.QtGui import QFont -from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEngineProfile +from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile, + QWebEnginePage) from qutebrowser.browser.webengine import spell from qutebrowser.config import config, websettings @@ -274,7 +275,8 @@ def _init_profiles(): def init(args): """Initialize the global QWebSettings.""" - if args.enable_webengine_inspector: + if (args.enable_webengine_inspector and + not hasattr(QWebEnginePage, 'setInspectedPage')): # only Qt < 5.11 os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = str(utils.random_port()) _init_profiles() diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index 292c80c6a..7a1bef736 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -86,7 +86,9 @@ def get_argparser(): "that this is a SECURITY RISK and you should not " "visit untrusted websites with the inspector turned " "on. See https://bugreports.qt.io/browse/QTBUG-50725 " - "for more details.") + "for more details. This is not needed anymore since " + "Qt 5.11 where the inspector is always enabled and " + "secure.") parser.add_argument('--json-args', help=argparse.SUPPRESS) parser.add_argument('--temp-basedir-restarted', help=argparse.SUPPRESS) diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 743cffd84..03aa9fada 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -163,7 +163,7 @@ Feature: Various utility commands. And I run :inspector Then the error "Please enable content.developer_extras before using the webinspector!" should be shown - @qtwebkit_skip + @qtwebkit_skip @qt<5.11 Scenario: Inspector without --enable-webengine-inspector When I run :inspector Then the error "QtWebEngine inspector is not enabled. See 'qutebrowser --help' for details." should be shown diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index 95b94fae3..75defe814 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -26,9 +26,10 @@ import logging import re import pytest - from PyQt5.QtCore import QProcess, qVersion +from tests import utils + ascii_locale = pytest.mark.skipif(sys.hexversion >= 0x03070000, reason="Python >= 3.7 doesn't force ASCII " @@ -257,6 +258,7 @@ def test_qt_arg(request, quteproc_new, tmpdir): quteproc_new.wait_for_quit() +@utils.skip_qt511 def test_webengine_inspector(request, quteproc_new): if not request.config.webengine: pytest.skip() diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index 834803f61..2e87a26f9 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -36,6 +36,8 @@ qt58 = pytest.mark.skipif( qtutils.version_check('5.9'), reason="Needs Qt 5.8 or earlier") qt59 = pytest.mark.skipif( not qtutils.version_check('5.9'), reason="Needs Qt 5.9 or newer") +skip_qt511 = pytest.mark.skipif( + qtutils.version_check('5.11'), reason="Needs Qt 5.10 or earlier") class PartialCompareOutcome: