Method RunScriptAsync
RunScriptAsync(string, IntPtr?)
Runs the given JavaScript code asynchronously and returns the result via a ScriptResult event.
public virtual void RunScriptAsync(string javascript, IntPtr? clientData = null)
Parameters
javascript
stringJavaScript code to execute.
clientData
IntPtr?Arbirary pointer to data that can be used in the result event. You can use IntPtr.Zero, new IntPtr(SomeInt) or pointer to some useful data in this parameter.
Remarks
The script result value can be retrieved via Text parameter or a ScriptResult event. If the execution fails IsError will return true. In this case additional script execution error information may be available via Text.
This function has a few platform-specific limitations:
When using WebKit v1 (wxGTK2), retrieving the result of script execution is unsupported. Running scripts functionality is fully supported when using WebKit v2 or later (wxGTK3).
When using WebKit (macOS), code execution is limited to 10MiB of memory and 10 seconds of execution time.
When using IE backend, scripts can only be executed when the current page is fully loaded and Loaded event was received. A script tag inside the page HTML is required in order to run JavaScript.
Under MSW converting JavaScript objects to JSON is not supported in the IE backend. WebBrowser implements its own conversion as a fallback for this case.
However it is not as full-featured or performing as the implementation of this functionality in the browser itself. It is recommended to use IELatest or Edge backends in which JSON conversion is done by the browser itself.