Use a separate JS world for :jseval
This commit is contained in:
parent
c9e3cc04cf
commit
8a35ebac7b
@ -1928,6 +1928,9 @@ class CommandDispatcher:
|
|||||||
world: Ignored on QtWebKit. On QtWebEngine, a world ID or name to
|
world: Ignored on QtWebKit. On QtWebEngine, a world ID or name to
|
||||||
run the snippet in.
|
run the snippet in.
|
||||||
"""
|
"""
|
||||||
|
if world is None:
|
||||||
|
world = usertypes.JsWorld.jseval
|
||||||
|
|
||||||
if quiet:
|
if quiet:
|
||||||
jseval_cb = None
|
jseval_cb = None
|
||||||
else:
|
else:
|
||||||
@ -1949,9 +1952,6 @@ class CommandDispatcher:
|
|||||||
message.info(self._win_id, out)
|
message.info(self._win_id, out)
|
||||||
|
|
||||||
widget = self._current_widget()
|
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')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
|
@ -53,6 +53,7 @@ _JS_WORLD_MAP = {
|
|||||||
usertypes.JsWorld.main: QWebEngineScript.MainWorld,
|
usertypes.JsWorld.main: QWebEngineScript.MainWorld,
|
||||||
usertypes.JsWorld.application: QWebEngineScript.ApplicationWorld,
|
usertypes.JsWorld.application: QWebEngineScript.ApplicationWorld,
|
||||||
usertypes.JsWorld.user: QWebEngineScript.UserWorld,
|
usertypes.JsWorld.user: QWebEngineScript.UserWorld,
|
||||||
|
usertypes.JsWorld.jseval: QWebEngineScript.UserWorld + 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -497,7 +498,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||||||
else:
|
else:
|
||||||
self._widget.page().runJavaScript(code, world_id, callback)
|
self._widget.page().runJavaScript(code, world_id, callback)
|
||||||
except TypeError:
|
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")
|
log.webview.warning("Ignoring world ID on Qt < 5.7")
|
||||||
# Qt < 5.7
|
# Qt < 5.7
|
||||||
if callback is None:
|
if callback is None:
|
||||||
|
@ -622,7 +622,7 @@ class WebKitTab(browsertab.AbstractTab):
|
|||||||
callback(frame.toHtml())
|
callback(frame.toHtml())
|
||||||
|
|
||||||
def run_js_async(self, code, callback=None, *, world=None):
|
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))
|
log.webview.warning("Ignoring world ID {}".format(world))
|
||||||
result = self._widget.page().mainFrame().evaluateJavaScript(code)
|
result = self._widget.page().mainFrame().evaluateJavaScript(code)
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
|
@ -262,7 +262,7 @@ arg2backend = {
|
|||||||
|
|
||||||
|
|
||||||
# JS world for QtWebEngine
|
# JS world for QtWebEngine
|
||||||
JsWorld = enum('JsWorld', ['main', 'application', 'user'])
|
JsWorld = enum('JsWorld', ['main', 'application', 'user', 'jseval'])
|
||||||
|
|
||||||
|
|
||||||
# Where a download should be saved
|
# Where a download should be saved
|
||||||
|
Loading…
Reference in New Issue
Block a user