WKWebView script message handlers not called on physical devices
Originator: | yannick.loriot | ||
Number: | rdar://18512488 | Date Originated: | |
Status: | Open | Resolved: | |
Product: | iOS SDK | Product Version: | |
Classification: | Serious Bug | Reproducible: | Always |
Summary: I have a small javascript which triggers some events via the webkit.messageHandlers property and the WKWebView which is listening to this events. On the simulator everything is ok, but on the device I received no events expect if I add the webview as subview of another one. Steps to Reproduce: 1. Create a small html page with a javascript which trigger an event 2. Create a WKWebViewConfiguration and add an handler for the event 3. Create the WKWebView and wait for the event (See gist: https://gist.github.com/YannickL/4a3a11073d3cedf7e7ec) Expected Results: I would received the event triggered by my script Actual Results: There is nothing on the device (everything is ok on the simulator) expect if I put the webview as subview Version: iOS 8.0.2 Notes: I would use the WKWebView to be able to work with websocket so I don't need to add the webview as subview. I just need to use the webkit engine. Configuration: iPad Mini Retina
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Workaround
We've discovered a workaround:
Only call your Javascript's initial function in
window.onload
, and make sure you've added the WKWebView as a subview somewhere, even if it's 0-width/height.UIApplication.sharedApplication.delegate.window.addSubview(webView)
works fine