diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 1e0d62c51..7e78b2621 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -812,15 +812,6 @@ class AbstractTab(QWidget): self.title_changed.emit(url.toDisplayString()) self.url_changed.emit(url) - url = self.url(requested=True) - - # Ignore blank QUrls to avoid crashes. - if not url.isValid(): - log.webview.debug("Not updating per-domain stylesheets due to the QUrl being blank") - return - - self._update_stylesheet(url) - @pyqtSlot() def _on_load_started(self): self._progress = 0 diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 5f0952bca..05bc843b7 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -790,14 +790,32 @@ class _WebEngineScripts(QObject): def connect_signals(self): config.instance.changed.connect(self._on_config_changed) + self._tab.url_changed.connect(self._update_stylesheet) + self._tab.load_finished.connect(self._on_load_finished) @pyqtSlot(str) def _on_config_changed(self, option): if option in ['scrolling.bar', 'content.user_stylesheets']: self._init_stylesheet() - url = self.url(requested=True) + url = self._tab.url(requested=True) self._update_stylesheet(url=url) + @pyqtSlot() + def _on_url_changed(self): + requested_url = self._tab.url(requested=True) + + # Ignore blank QUrls to avoid crashes. + if not requested_url.isValid(): + log.webview.debug("Not updating per-domain stylesheets due to the QUrl being blank") + return + + self._update_stylesheet(requested_url) + + @pyqtSlot() + def _on_load_finished(self): + url = self._tab.url(requested=True) + self._update_stylesheet(url) + def _update_stylesheet(self, url=None): """Update the custom stylesheet in existing tabs.""" css = shared.get_user_stylesheet(url=url) @@ -1226,9 +1244,6 @@ class WebEngineTab(browsertab.AbstractTab): # the old icon is still displayed. self.icon_changed.emit(QIcon()) - url = self.url(requested=True) - self._update_stylesheet(url) - @pyqtSlot(QUrl) def _on_predicted_navigation(self, url): """If we know we're going to visit an URL soon, change the settings.