Add --world to :jseval
This commit is contained in:
parent
a16c5a6a25
commit
b2608d7697
@ -438,7 +438,7 @@ Note: Due a bug in Qt, the inspector will show incorrect request headers in the
|
|||||||
|
|
||||||
[[jseval]]
|
[[jseval]]
|
||||||
=== jseval
|
=== jseval
|
||||||
Syntax: +:jseval [*--quiet*] 'js-code'+
|
Syntax: +:jseval [*--quiet*] [*--world* 'world'] 'js-code'+
|
||||||
|
|
||||||
Evaluate a JavaScript string.
|
Evaluate a JavaScript string.
|
||||||
|
|
||||||
@ -447,6 +447,8 @@ Evaluate a JavaScript string.
|
|||||||
|
|
||||||
==== optional arguments
|
==== optional arguments
|
||||||
* +*-q*+, +*--quiet*+: Don't show resulting JS object.
|
* +*-q*+, +*--quiet*+: Don't show resulting JS object.
|
||||||
|
* +*-w*+, +*--world*+: Ignored on QtWebKit. On QtWebEngine, which JS world/context to run the snippet in.
|
||||||
|
|
||||||
|
|
||||||
==== note
|
==== note
|
||||||
* This command does not split arguments after the last argument and handles quotes literally.
|
* This command does not split arguments after the last argument and handles quotes literally.
|
||||||
|
@ -1918,12 +1918,14 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
maxsplit=0, no_cmd_split=True)
|
maxsplit=0, no_cmd_split=True)
|
||||||
def jseval(self, js_code, quiet=False):
|
def jseval(self, js_code, quiet=False, *, world: int=None):
|
||||||
"""Evaluate a JavaScript string.
|
"""Evaluate a JavaScript string.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
js_code: The string to evaluate.
|
js_code: The string to evaluate.
|
||||||
quiet: Don't show resulting JS object.
|
quiet: Don't show resulting JS object.
|
||||||
|
world: Ignored on QtWebKit. On QtWebEngine, a world ID to run the
|
||||||
|
snippet in.
|
||||||
"""
|
"""
|
||||||
if quiet:
|
if quiet:
|
||||||
jseval_cb = None
|
jseval_cb = None
|
||||||
@ -1945,7 +1947,11 @@ class CommandDispatcher:
|
|||||||
out = out[:5000] + ' [...trimmed...]'
|
out = out[:5000] + ' [...trimmed...]'
|
||||||
message.info(self._win_id, out)
|
message.info(self._win_id, out)
|
||||||
|
|
||||||
self._current_widget().run_js_async(js_code, callback=jseval_cb)
|
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)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def fake_key(self, keystring, global_=False):
|
def fake_key(self, keystring, global_=False):
|
||||||
|
@ -87,6 +87,28 @@ Feature: Various utility commands.
|
|||||||
When I run :jseval Array(5002).join("x")
|
When I run :jseval Array(5002).join("x")
|
||||||
Then the message "x* [...trimmed...]" should be shown
|
Then the message "x* [...trimmed...]" should be shown
|
||||||
|
|
||||||
|
@qtwebengine_skip
|
||||||
|
Scenario: :jseval with --world on QtWebKit
|
||||||
|
When I set general -> log-javascript-console to info
|
||||||
|
And I run :jseval --world=1 console.log("Hello from JS!");
|
||||||
|
And I wait for the javascript message "Hello from JS!"
|
||||||
|
Then "Ignoring world ID 1" should be logged
|
||||||
|
|
||||||
|
@qtwebkit_skip
|
||||||
|
Scenario: :jseval uses separate world without --world
|
||||||
|
When I set general -> log-javascript-console to info
|
||||||
|
And I open data/misc/jseval.html
|
||||||
|
And I run :jseval do_log()
|
||||||
|
Then the javascript message "Hello from the page!" should not be logged
|
||||||
|
And the javascript message "Uncaught ReferenceError: do_log is not defined" should be logged
|
||||||
|
|
||||||
|
@qtwebkit_skip
|
||||||
|
Scenario: :jseval using the main world
|
||||||
|
When I set general -> log-javascript-console to info
|
||||||
|
And I open data/misc/jseval.html
|
||||||
|
And I run :jseval --world 0 do_log()
|
||||||
|
Then the javascript message "Hello from the page!" should be logged
|
||||||
|
|
||||||
# :debug-webaction
|
# :debug-webaction
|
||||||
|
|
||||||
Scenario: :debug-webaction with valid value
|
Scenario: :debug-webaction with valid value
|
||||||
|
Loading…
Reference in New Issue
Block a user