diff --git a/Dockerfile b/Dockerfile index cfe31cce8..1bc557962 100644 --- a/Dockerfile +++ b/Dockerfile @@ -115,6 +115,9 @@ RUN pip3 install /app ENV PYTHONPATH $PYTHONPATH:/app #ENV QT_DEBUG_PLUGINS=1 +# Enable Chrome DevTools Protocol (CDP) in QtWebEngine +ENV QTWEBENGINE_REMOTE_DEBUGGING "127.0.0.1:9050" + # Chromium refuses to start under root RUN groupadd -r splash && useradd --no-log-init --create-home -r -g splash splash RUN chown -R splash:splash /app diff --git a/dockerfiles/splash/install-python-splash-deps.sh b/dockerfiles/splash/install-python-splash-deps.sh index a9b535d2f..19298f8bf 100755 --- a/dockerfiles/splash/install-python-splash-deps.sh +++ b/dockerfiles/splash/install-python-splash-deps.sh @@ -5,7 +5,7 @@ install_python_deps () { # Install python-level dependencies. ${_PYTHON} -m pip install -U pip setuptools six && \ ${_PYTHON} -m pip install \ - qt5reactor==0.5 \ + asyncqt==0.7.0 \ psutil==5.0.0 \ "Twisted[http2]==19.7.0" \ adblockparser==0.7 \ @@ -17,4 +17,4 @@ install_python_deps () { ${_PYTHON} -m pip install https://github.com/sunu/pyre2/archive/c610be52c3b5379b257d56fc0669d022fd70082a.zip#egg=re2 } -install_python_deps \ No newline at end of file +install_python_deps diff --git a/requirements.txt b/requirements.txt index 8fe7531f4..086a03615 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # install PyQt5 (Splash is tested on PyQT 5.13) # and the following packages: twisted[http2] == 19.7.0 -qt5reactor +asyncqt == 0.7.0 psutil adblockparser >= 0.5 https://github.com/sunu/pyre2/archive/c610be52c3b5379b257d56fc0669d022fd70082a.zip#egg=re2 diff --git a/setup.py b/setup.py index 06608f6c3..2d0d6206a 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ def get_version(): 'zip_safe': False, 'install_requires': [ 'Twisted[http2] >= 19.7.0', - 'qt5reactor', + 'asyncqt', 'psutil', 'adblockparser', 'xvfbwrapper', diff --git a/splash/qtutils.py b/splash/qtutils.py index 759033dc2..538e9b771 100644 --- a/splash/qtutils.py +++ b/splash/qtutils.py @@ -139,6 +139,9 @@ def awake(self): diff = time.time() - self.blockedAt log.msg("awake; block time: %0.4f" % diff, system="QAbstractEventDispatcher") _qtapp = QApp(sys.argv) + # we have to set this, because otherwise the program may quit when + # the last web view window is closed. + _qtapp.setQuitOnLastWindowClosed(False) return _qtapp diff --git a/splash/server.py b/splash/server.py index 7680810dc..57c22cc84 100644 --- a/splash/server.py +++ b/splash/server.py @@ -1,3 +1,4 @@ +import asyncio import os import sys import optparse @@ -7,6 +8,9 @@ import functools import faulthandler +from asyncqt import QEventLoop +from twisted.internet import asyncioreactor + from splash import defaults, __version__ from splash import xvfb from splash.qtutils import init_qt_app @@ -15,10 +19,14 @@ def install_qtreactor(verbose): - init_qt_app(verbose) - import qt5reactor - qt5reactor.install() - + """ + Install asyncqt eventloop for asyncio, and then install the + asyncioreactor for twisted. + """ + qtapp = init_qt_app(verbose) + loop = QEventLoop(qtapp) + asyncio.set_event_loop(loop) + asyncioreactor.install(loop) def parse_opts(jupyter=False, argv=None): if argv is None: