When using drawViewHierarchyInRect:afterScreenUpdates: to capture WKWebView content for rendering to a Metal texture (for 3D browser widget), video elements (such as HTML5 <video> tags or embedded video players) appear as black/blank in the captured image.
Environment:
• Unreal Engine 5.3.2
• iOS 15+ / iOS 16+
• WKWebView with Metal texture rendering
-(void)updateWebViewMetalTexture:(id<MTLTexture>)texture
{
@autoreleasepool {
UIGraphicsBeginImageContextWithOptions(WebView.frame.size, NO, 1\.0f);
\[WebView drawViewHierarchyInRect:WebView.bounds afterScreenUpdates:NO];
UIImage \*image \= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// ... copy image data to Metal texture
\[texture replaceRegion:MTLRegionMake2D(0, 0, width, height)
mipmapLevel:0
withBytes:CGBitmapContextGetData(context)
bytesPerRow:4 \* width];
}
}
I have also tried using WKSnapshotConfiguration with takeSnapshotWithConfiguration, but video content still appears as black.
Questions:
Has anyone successfully captured WKWebView video content to a texture on iOS?
[Attachment Removed]