Reputation: 4992
Im following this example to retrieve a DOM element in swift: https://www.hackingwithswift.com/example-code/wkwebview/how-to-run-javascript-on-a-wkwebview-with-evaluatejavascript
wkWebView.evaluateJavaScript("document.body.offsetHeight") { (result, error) in
if error != nil {
print(result)
} else {
print(error ?? "Error")
}
}
But im getting this error:
nil
Error
App(28447,0x137b3bc40) malloc: *** error for object 0x170b9140:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
If I just do a console log and inspect in safari it works fine:
wkWebView.evaluateJavaScript("console.log('Hello World!')")
Hello World!
Upvotes: 1
Views: 83
Reputation: 5303
Your error is nil. You actually got results.
Either change "!=" to "=="
or change the whole line:
if error != nil {
to
if result != nil {
Upvotes: 1