summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-10-27 17:54:08 +1300
committertoofar <toofar@spalge.com>2023-10-27 18:20:44 +1300
commit3bde102fe0a317dc97b459da7cfeaffc1c439932 (patch)
tree38d97a9544cbda3d386b6f238932bd5e5f0b87cb
parent82e24430491591d905ea64c7662c2b714398b159 (diff)
downloadqutebrowser-3bde102fe0a317dc97b459da7cfeaffc1c439932.tar.gz
qutebrowser-3bde102fe0a317dc97b459da7cfeaffc1c439932.zip
run pakjoy for real at application boot
It all just works! Changes from the `__main__` implementation down below: * copy the whole resources directory instead of just the one file: looking at the implementation around QTWEBENGINE_RESOURCES_PATH it uses the main resources file to find the one directory and then loads the other resources from that dir. So I'm assuming it was crashing because it couldn't find the other resources. Stack trace was: #1 0x00007fffe95f1dca in content::ContentMainRunnerImpl::Initialize(content::ContentMainParams) () from /usr/local/Qt-6.6.0/lib/libQt6WebEngineCore.so.6 #2 0x00007fffe628cf09 in QtWebEngineCore::WebEngineContext::WebEngineContext() () from /usr/local/Qt-6.6.0/lib/libQt6WebEngineCore.so.6 #3 0x00007fffe628dfa4 in QtWebEngineCore::WebEngineContext::current() () from /usr/local/Qt-6.6.0/lib/libQt6WebEngineCore.so.6 #4 0x00000210b845c780 in ?? () #5 0x00000210b845c780 in ?? () #6 0x00007fffffffd480 in ?? () #7 0x00007fffe62391bb in QtWebEngineCore::ProfileAdapter::ProfileAdapter(QString const&) () from /usr/local/Qt-6.6.0/lib/libQt6WebEngineCore.so.6 * write stuff to our cache dir, not tmp ;) I haven't actually checked this fixes an affected version of Qt (need to rebuild or get from riverbank pypi). But I unpacked the pak file and it has the right fake URL in it.
-rw-r--r--qutebrowser/app.py6
-rw-r--r--qutebrowser/misc/pakjoy.py25
2 files changed, 30 insertions, 1 deletions
diff --git a/qutebrowser/app.py b/qutebrowser/app.py
index 778c248c2..4a6284eb1 100644
--- a/qutebrowser/app.py
+++ b/qutebrowser/app.py
@@ -50,7 +50,7 @@ from qutebrowser.keyinput import macros, eventfilter
from qutebrowser.mainwindow import mainwindow, prompt, windowundo
from qutebrowser.misc import (ipc, savemanager, sessions, crashsignal,
earlyinit, sql, cmdhistory, backendproblem,
- objects, quitter, nativeeventfilter)
+ objects, quitter, nativeeventfilter, pakjoy)
from qutebrowser.utils import (log, version, message, utils, urlutils, objreg,
resources, usertypes, standarddir,
error, qtutils, debug)
@@ -76,6 +76,10 @@ def run(args):
log.init.debug("Initializing config...")
configinit.early_init(args)
+ # Run after we've imported Qt but before webengine is initialized.
+ # TODO: check: backend, Qt version, frozen
+ pakjoy.patch()
+
log.init.debug("Initializing application...")
app = Application(args)
objects.qapp = app
diff --git a/qutebrowser/misc/pakjoy.py b/qutebrowser/misc/pakjoy.py
index cdf2b4744..7e0d139c4 100644
--- a/qutebrowser/misc/pakjoy.py
+++ b/qutebrowser/misc/pakjoy.py
@@ -26,10 +26,14 @@ This is a "best effort" parser. If it errors out, we don't apply the workaround
instead of crashing.
"""
+import os
+import shutil
+import pathlib
import dataclasses
from typing import ClassVar, IO, Optional, Dict, Tuple
from qutebrowser.misc import binparsing
+from qutebrowser.utils import qtutils, standarddir
HANGOUTS_MARKER = b"// Extension ID: nkeimhogjdpnpccoofpliimaahmaaome"
HANGOUTS_ID = 36197 # as found by toofar
@@ -139,6 +143,27 @@ class PakParser:
raise binparsing.ParseError("Couldn't find hangouts manifest")
+def patch():
+ resources_path = qtutils.library_path(qtutils.LibraryPath.data) / "resources"
+ work_dir = pathlib.Path(standarddir.cache()) / "webengine_resources_pak_quirk"
+ patched_file = work_dir / "qtwebengine_resources.pak"
+
+ print(f"{work_dir=} {work_dir.exists()=}")
+ print(f"{resources_path=}")
+ if work_dir.exists():
+ shutil.rmtree(work_dir)
+
+ shutil.copytree(resources_path, work_dir)
+
+ with open(patched_file, "r+b") as f:
+ parser = PakParser(f)
+ offset = parser.find_patch_offset()
+ f.seek(offset)
+ f.write(REPLACEMENT_URL)
+
+ os.environ["QTWEBENGINE_RESOURCES_PATH"] = str(work_dir)
+
+
if __name__ == "__main__":
import shutil
shutil.copy("/usr/share/qt6/resources/qtwebengine_resources.pak", "/tmp/test.pak")