WKWebView drawViewHierarchyInRect doesn't render webGL content on phone
| Originator: | jed | ||
| Number: | rdar://27315173 | Date Originated: | 13 July 2016 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | iOS 9.3.2 (13F69) |
| Classification: | Reproducible: | yes |
Summary:
My app has a WKWebView that displays a web page containing some webGL content. I use drawViewHierarchyInRect to render the WKWebView to an image after the web page has loaded. This works fine on the simulator but on a phone the webGL content is not rendered to the image. The rest of the web page is rendered OK but on the phone the drawViewHierarchyInRect call returns false.
Steps to Reproduce:
I have created a test Xcode project to illustrate the problem:
https://github.com/jedsoane/TestWKWebViewImageCapture
The basic idea is:
1. Added a WKWebView. Get it to load a page containing webGL content, e.g. http://madebyevan.com/webgl-water/
2. Add a UIImageView to preview the image we will create.
3. Add a button to connect to a method that calls drawViewHierarchyInRect e.g.
@IBAction func takePhoto(sender: AnyObject)
{
UIGraphicsBeginImageContextWithOptions(webView.bounds.size, true, 0.0)
let drewOK = webView.drawViewHierarchyInRect(webView.bounds, afterScreenUpdates: true)
if (!drewOK)
{
print("drawViewHierarchyInRect failed")
}
let overlayImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
photoPreview.image = overlayImage
}
Run the app, wait for page to load, tap the button to create an image.
Expected Results:
I would expect the webGL to be rendered to the image along with the rest of the web page content.
Actual Results:
Web page content, excluding the webGL canvas, is rendered to the image.
Version:
iOS 9.3.2 (13F69)
Notes:
Also tested on the iOS 10 beta 2. Same problem there.
Configuration:
iPhone 6S and iPhone 6S Plus
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!