I have successfully set up a WKWebView ScriptMessageHandler to receive messages from inside my webview. I'm then using evaluateJavaScript
to send responses back into the webview. This works fine when everything is executed on the main frame of the view.
However, when I try to do this inside an iFrame I run into difficulties. I still receive the message in the message handler (complete with WKFrameInfo
to tell me where it came from) but I can't find any way to run evalateJavaScript
targeting that frame. I could use a window.frames
hack in my evaluated JavaScript, but if the iFrame is of a different origin than the parent frame then I'm going to run into cross-domain errors.
Is there any way to identify a frame inside WKWebview, and evaluate JS on it?
Three years later: iOS 14 will support this.
https://developer.apple.com/documentation/webkit/wkwebview/3656442-evaluatejavascript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With