Don't get everything on macOS web screenshot

w I'm trying to take a cocoa webview screenshot with this code:

NSBitmapImageRep *bitmapRepRight = [[webView mainFrame].frameView bitmapImageRepForCachingDisplayInRect:cacheRect]; [[[webView mainFrame].frameView documentView] layout]; [[webView mainFrame].frameView cacheDisplayInRect:cacheRect toBitmapImageRep:bitmapRepRight]; return [bitmapRepRight CGImage]; 

This code is called from the frame function - (void) webView: (WebView *) didFinishLoadForFrame: (WebFrame *).

I get only the background image of the page, but neither text nor images.

If I call it using [self performSelector: @selector (addPagesToCache) withObject: nil afterDelay: 0.01]; then it works, but it’s not a completely clean way.

What could be the problem and how can I fix it?

+4
source share
1 answer

If your webview is visible (in a window), you can use CGWindowListCreateImage to partially image the window. It is also a workaround, not an ideal solution.

0
source

All Articles