Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screenshot Safari from Share Extension

Is it possible to perform a screenshot of the current visible zone of the webview in Safari from a Share Extension? I could use windows, but UIApplication isn't supported on extensions so I can't access to that window.

like image 913
Alvaro Franco Avatar asked Aug 28 '14 15:08

Alvaro Franco


People also ask

How do I take a screenshot in Safari?

Press and hold these three keys together: Shift, Command, and 4. Drag the crosshair to select the area of the screen to capture. To move the selection, press and hold Space bar while dragging. To cancel taking the screenshot, press the Esc (Escape) key.


1 Answers

You can't since UIApplication can't be reached from an extension. You cannot get the first UIWindow, which is the Safari layer, so you have to play with the Javascript preprocessing file that the extensions have. So just create a Javascript file that, when sent to Safari, generates a base64 string with the current visible zone image data. Take that string through the kUTTypePropertyList identifier in your extension. Since that should be NSData, generate the UIImage from there, by using +imageWithData. That is what you're looking for, without having to load the page again, preventing a second load and a bad image if the webpage requires of a login.

like image 137
skozz Avatar answered Oct 17 '22 00:10

skozz