Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

evaluateJavaScript in a WKWebView's iframe?

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?

like image 620
Alastair Avatar asked Feb 16 '17 19:02

Alastair


1 Answers

Three years later: iOS 14 will support this.

https://developer.apple.com/documentation/webkit/wkwebview/3656442-evaluatejavascript

like image 129
Alastair Avatar answered Nov 04 '22 13:11

Alastair