Try to fix intermittent per-domain stylesheets
This commit is contained in:
parent
f391d726c0
commit
b04934c2b3
@ -812,6 +812,9 @@ class AbstractTab(QWidget):
|
||||
self.title_changed.emit(url.toDisplayString())
|
||||
self.url_changed.emit(url)
|
||||
|
||||
url = self.url(requested=True)
|
||||
self._update_stylesheet(url)
|
||||
|
||||
@pyqtSlot()
|
||||
def _on_load_started(self):
|
||||
self._progress = 0
|
||||
|
@ -801,7 +801,7 @@ class _WebEngineScripts(QObject):
|
||||
def _update_stylesheet(self, url=None):
|
||||
"""Update the custom stylesheet in existing tabs."""
|
||||
css = shared.get_user_stylesheet(url=url)
|
||||
code = javascript.assemble('stylesheet', 'set_css', css)
|
||||
code = javascript.assemble('stylesheet', 'set_css', css, delay=True)
|
||||
self._tab.run_js_async(code)
|
||||
|
||||
def _inject_early_js(self, name, js_code, *,
|
||||
@ -1226,9 +1226,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.
|
||||
|
@ -64,14 +64,28 @@ def _convert_js_arg(arg):
|
||||
arg, type(arg).__name__))
|
||||
|
||||
|
||||
def assemble(module, function, *args):
|
||||
def assemble(module, function, *args, delay=False):
|
||||
"""Assemble a javascript file and a function call."""
|
||||
js_args = ', '.join(_convert_js_arg(arg) for arg in args)
|
||||
if module == 'window':
|
||||
parts = ['window', function]
|
||||
else:
|
||||
parts = ['window', '_qutebrowser', module, function]
|
||||
code = '"use strict";\n{}({});'.format('.'.join(parts), js_args)
|
||||
if delay:
|
||||
code = '''
|
||||
"use strict";
|
||||
if (document.readyState !== "loading") {{
|
||||
{parts}({args});
|
||||
}} else {{
|
||||
window.addEventListener("DOMContentLoaded", () => {{
|
||||
{parts}({args});
|
||||
}});
|
||||
}}
|
||||
'''
|
||||
code = code.format(parts='.'.join(parts), args=js_args)
|
||||
else:
|
||||
code = '"use strict";\n{}({});'.format('.'.join(parts), js_args)
|
||||
# print(code)
|
||||
return code
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user