I am trying to create an iOS tweak that makes WKWebView run certain JavaScript code after it finishes loading a page. I made a simple iOS app with an embedded WKWebview, loading the url as “https://google.com” and add the app’s bundle id to the tweak plist. I intent to let the webview evaluate JavaScript code like:
document.body.style.backgroundColor = 'red'
...however nothing happened ( as the google’s background should turn into red ). Is there any syntax error or something missing in my code? By the way, how do you debug a iOS tweak or .x file? I can’t seem to find any log or breakpoint like in Xcode
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
%hook WKWebview
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
%orig;
NSLog(@"Webview did finish loading");
[webView evaluateJavaScript:@"document.body.style.backgroundColor = 'red'" completionHandler:nil];
}
%end
I tried to call - [WKWebView evaluateJavaScript:completionHandler:] method as followed by Objective-C syntax. I expect the google's home page to turn red but no change happened