0

As I debug my app to find why the webview dowsn't receive my messages, I found out that another WkWebview (let's call it B) was created on top of my existing webview (A). Since I only have reference to A, I'm trying to evaluate js directly on B using it's memory address. what is the correct way to do that in lldb?

Based on this answer, I've tried: settings set target.language swift e -- import WKWebview e -- let $webView = unsafeBitCast(0x13299e400, to:WKWebview.self)

in order to call webView.evaluateJavaScript, but lldb says:

let $webView = unsafeBitCast(0x13299e400, to:WKWebview.self)
               ^

error: <EXPR>:3:46: error: cannot convert value of type 'module<WKWebview>' to expected argument type 'U.Type'
let $webView = unsafeBitCast(0x13299e400, to:WKWebview.self)```
Yarden
  • 45
  • 6
  • It might be easier to achieve this by switching to objective-c mode of lldb like this: `e -l objc -- [0x13299e400 evaluateJavaScript:@"your javascript code" completionHandler:nil]` – Kamil.S Jun 01 '20 at 09:18
  • @Kamil.S I had to make a few adjustments but it does seem to work. Thank you for your answer! – Yarden Jun 18 '20 at 09:24
  • please post your final solution as an answer for future readers. – Kamil.S Jun 18 '20 at 10:37

1 Answers1

0

Thanks to @Kamil.S I managed to get it right. The complete steps were:

(lldb) e @import <WKWebview.h>
(lldb) e NSString *$js = <my javascript to evaluate>
(lldb) e (void)[(id)0x10504ea00 evaluateJavaScript:$js completionHandler:nil]
Yarden
  • 45
  • 6