summaryrefslogtreecommitdiff
path: root/qutebrowser
diff options
context:
space:
mode:
authorJimmy <jimmy@spalge.com>2021-11-28 11:45:14 +1300
committerJimmy <jimmy@spalge.com>2021-11-28 11:45:14 +1300
commit22312dca486b41569590e6b7681edb95472cb67c (patch)
tree6eb691949ff3e106f0eb1fbe3061a0e937520622 /qutebrowser
parent2877c9529a780c6ee56b83bed2b5515c1c689a38 (diff)
downloadqutebrowser-22312dca486b41569590e6b7681edb95472cb67c.tar.gz
qutebrowser-22312dca486b41569590e6b7681edb95472cb67c.zip
Switch back to JS WorldId Enums with .value
ba6055d5d38a3f3 included some hasty fixups that caused a couple of places to the from ApplicationWorld to 1, instead of 2. This change mostly reverts that can calls .value in a couple of places since the WebEngine APIs wants ints for some reason.
Diffstat (limited to 'qutebrowser')
-rw-r--r--qutebrowser/browser/webengine/webenginetab.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py
index 48991dc31..31af8ef20 100644
--- a/qutebrowser/browser/webengine/webenginetab.py
+++ b/qutebrowser/browser/webengine/webenginetab.py
@@ -45,10 +45,10 @@ from qutebrowser.misc import objects, miscwidgets
# Mapping worlds from usertypes.JsWorld to QWebEngineScript world IDs.
_JS_WORLD_MAP = {
- usertypes.JsWorld.main: 1,
- usertypes.JsWorld.application: 2,
- usertypes.JsWorld.user: 3,
- usertypes.JsWorld.jseval: 4,
+ usertypes.JsWorld.main: QWebEngineScript.ScriptWorldId.MainWorld,
+ usertypes.JsWorld.application: QWebEngineScript.ScriptWorldId.ApplicationWorld,
+ usertypes.JsWorld.user: QWebEngineScript.ScriptWorldId.UserWorld,
+ usertypes.JsWorld.jseval: QWebEngineScript.ScriptWorldId.UserWorld + 1,
}
@@ -994,7 +994,7 @@ class _Quirk:
filename: str
injection_point: QWebEngineScript.InjectionPoint = (
QWebEngineScript.InjectionPoint.DocumentCreation)
- world: int = 1
+ world: QWebEngineScript.ScriptWorldId = QWebEngineScript.ScriptWorldId.MainWorld
predicate: bool = True
name: Optional[str] = None
@@ -1033,14 +1033,14 @@ class _WebEngineScripts(QObject):
self._tab.run_js_async(code)
def _inject_js(self, name, js_code, *,
- world=2,
+ world=QWebEngineScript.ScriptWorldId.ApplicationWorld,
injection_point=QWebEngineScript.InjectionPoint.DocumentCreation,
subframes=False):
"""Inject the given script to run early on a page load."""
script = QWebEngineScript()
script.setInjectionPoint(injection_point)
script.setSourceCode(js_code)
- script.setWorldId(world)
+ script.setWorldId(world.value)
script.setRunsOnSubFrames(subframes)
script.setName(f'_qute_{name}')
self._widget.page().scripts().insert(script)
@@ -1172,7 +1172,7 @@ class _WebEngineScripts(QObject):
_Quirk(
'whatsapp_web',
injection_point=QWebEngineScript.InjectionPoint.DocumentReady,
- world=1,
+ world=QWebEngineScript.ScriptWorldId.ApplicationWorld,
),
_Quirk('discord'),
_Quirk(
@@ -1332,7 +1332,9 @@ class WebEngineTab(browsertab.AbstractTab):
def run_js_async(self, code, callback=None, *, world=None):
world_id_type = Union[QWebEngineScript.ScriptWorldId, int]
if world is None:
- world_id: world_id_type = 1
+ world_id: world_id_type = _JS_WORLD_MAP[
+ usertypes.JsWorld.application
+ ].value
elif isinstance(world, int):
world_id = world
if not 0 <= world_id <= qtutils.MAX_WORLD_ID:
@@ -1340,7 +1342,7 @@ class WebEngineTab(browsertab.AbstractTab):
"World ID should be between 0 and {}"
.format(qtutils.MAX_WORLD_ID))
else:
- world_id = _JS_WORLD_MAP[world]
+ world_id = _JS_WORLD_MAP[world].value
if callback is None:
self._widget.page().runJavaScript(code, world_id)