WKWebView takeSnapshot does not work on iOS 13

Number:rdar://FB402555 Date Originated:03/6/2020
Status:Resolved Resolved:03/13/2020
Product:WebKit Product Version:iOS13
Classification:bug Reproducible:iOS13
I need to take a screenshot of WebView while app in Background.

But on iOS13 method "takeSnapshotWithConfiguration:completionHandler:" of WKWebView does not work. completionHandler never fires when an app does a background task.

This works well on iOS12. Also, it works on iOS13 while app in the foreground.

Reproduce: see demo project to reproduce https://github.com/Jnis/WebView-Snapshot . Also see videos there.

Expected:  takeSnapshotWithConfiguration:completionHandler call completionHandler with image while app is in background

Actual result:

[self.wkwebView takeSnapshotWithConfiguration:configuration completionHandler:^(UIImage * _Nullable snapshotImage, NSError * _Nullable error) {
   // this never calls on iOS13 while app in the background. But iOS12 works well.

Thank you! 
( https://forums.developer.apple.com/message/402555#402555 )


Solution: setting WKSnapshotConfiguration’s afterScreenUpdates property to NO

WKSnapshotConfiguration *configuration = [WKSnapshotConfiguration new];
if (@available(iOS 13.0, *)) {
configuration.afterScreenUpdates = NO;

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!