WKWebView takeSnapshot does not work on iOS 13

I need take screenshot of WebView while app in Background.

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

This works well on iOS12. Also it works on iOS13 while app in 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 call on iOS13 while app in background. But iOS12 works well.

}];


Thank you!

Solution: setting WKSnapshotConfiguration’s afterScreenUpdates property to NO


WKSnapshotConfiguration *configuration = [WKSnapshotConfiguration new];
if (@available(iOS 13.0, *)) {
    configuration.afterScreenUpdates = NO;
}
WKWebView takeSnapshot does not work on iOS 13
 
 
Q