why is window.webkit undefined in javascript executing in a page loaded in WkWebView?

I have a WkWebView in an application developed to run in iOS 8 or above. In order for the browser's code to communicate with my app, it needs to execute javascript utilizing the webkit's messageHandlers, like this, where my handler's name is "NAME":

window.webkit.messageHandlers.NAME.postMessage('hello from javascript running in the hosted page!');


I've added code at the app like:

[wbConfig.userContentController addScriptMessageHandler:self name:@"NAME"];

_webView = [[WKWebView alloc] initWithFrame: [_webContainer bounds] configuration:wbConfig];


But when I run it in the simulator, window.webkit does not even exist. I'm baffled because nobody else has reported this issue. I must be doing something wrong?

Oh, with iOS 9 simulator, my WkWebView does not even seem to work. I've downloaded and am using the ios 8.4 simulator. Could that be the issue?

Perhaps the web page redefined window.webkit like this one does:

http://www.i-programmer.info/news/193-android/9159-amazon-reports-underground-success.html

Hi, I am facing a similar issue right now. Did you get any solution why window.webkit appears to be undefined.

why is window.webkit undefined in javascript executing in a page loaded in WkWebView?
 
 
Q