无法在MacOS网络视图屏幕截图中获取所有内容



w我正在尝试使用以下代码捕获可可网络视图的屏幕截图:

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

此代码从 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame 函数调用。

我只得到页面的背景,但没有文字也没有图像。

如果我使用 [self performSelector:@selector(addPagesToCache) withObject:nil afterDelay:0.01]; 然后它有效,但这根本不是一种干净的方式。

可能是什么问题,我该如何解决?

如果您的 Web 视图可见(在窗口中),则可以使用 CGWindowListCreateImage 拍摄窗口的部分图像。这也是一种解决方法,而不是完美的解决方案。

最新更新