Use a separate JS world for :jseval

This commit is contained in:
Florian Bruhin 2016-09-12 18:27:51 +02:00
parent c9e3cc04cf
commit 8a35ebac7b
4 changed files with 8 additions and 7 deletions

View File

@ -1928,6 +1928,9 @@ class CommandDispatcher:
world: Ignored on QtWebKit. On QtWebEngine, a world ID or name to
run the snippet in.
"""
if world is None:
world = usertypes.JsWorld.jseval
if quiet:
jseval_cb = None
else:
@ -1949,10 +1952,7 @@ class CommandDispatcher:
message.info(self._win_id, out)
widget = self._current_widget()
if world is None:
widget.run_js_async(js_code, callback=jseval_cb)
else:
widget.run_js_async(js_code, callback=jseval_cb, world=world)
widget.run_js_async(js_code, callback=jseval_cb, world=world)
@cmdutils.register(instance='command-dispatcher', scope='window')
def fake_key(self, keystring, global_=False):

View File

@ -53,6 +53,7 @@ _JS_WORLD_MAP = {
usertypes.JsWorld.main: QWebEngineScript.MainWorld,
usertypes.JsWorld.application: QWebEngineScript.ApplicationWorld,
usertypes.JsWorld.user: QWebEngineScript.UserWorld,
usertypes.JsWorld.jseval: QWebEngineScript.UserWorld + 1,
}
@ -497,7 +498,7 @@ class WebEngineTab(browsertab.AbstractTab):
else:
self._widget.page().runJavaScript(code, world_id, callback)
except TypeError:
if world is not None:
if world is not None and world != usertypes.JsWorld.jseval:
log.webview.warning("Ignoring world ID on Qt < 5.7")
# Qt < 5.7
if callback is None:

View File

@ -622,7 +622,7 @@ class WebKitTab(browsertab.AbstractTab):
callback(frame.toHtml())
def run_js_async(self, code, callback=None, *, world=None):
if world is not None:
if world is not None and world != usertypes.JsWorld.jseval:
log.webview.warning("Ignoring world ID {}".format(world))
result = self._widget.page().mainFrame().evaluateJavaScript(code)
if callback is not None:

View File

@ -262,7 +262,7 @@ arg2backend = {
# JS world for QtWebEngine
JsWorld = enum('JsWorld', ['main', 'application', 'user'])
JsWorld = enum('JsWorld', ['main', 'application', 'user', 'jseval'])
# Where a download should be saved