evaluateJavaScript(_:completionHandler:)
Evaluates the specified JavaScript string.
Declaration
func evaluateJavaScript(_ javaScriptString: String, completionHandler: (@MainActor @Sendable (Any?, (any Error)?) -> Void)? = nil)func evaluateJavaScript(_ javaScriptString: String) async throws -> Any?Parameters
- javaScriptString:
The JavaScript string to evaluate.
- completionHandler:
A handler block to execute when script evaluation finishes. The method calls your block whether script evaluation completes successfully or fails. The block has no return value and takes the following parameters:
- object
The result of the script evaluation, or
nilif an error occurred.- error
nilon success, or an error object with information about the problem.
Discussion
After evaluating the script, this method executes the completion handler block with either the result of the script evaluation or an error. The completion handler always runs on the app’s main thread.