0

In the Share Extension for Safari, is it possible to take a screenshot and save it to Userdefaults so my app can access it ?

Would this be a recommended way of capturing a screenshot of the browser from an app extension ?

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
NetCod
  • 191
  • 1
  • 2
  • 12
  • I guess there is only a hacky solution for this. Like hiding the webView behind another view and then use UIGraphicsEndImageContext. – andreaspfr Dec 30 '16 at 00:11
  • Thanks, edited the question. I am looking to do this from Safari when the browser is open now and pass this to my application. – NetCod Dec 30 '16 at 00:24

1 Answers1

0

You do not have access to Safari when your extension opens. Extensions run in their own processes, and their view context is outside that of Safari.

An interesting workaround would be to use NSExtensionJavaScriptPreprocessingFile with a JS file that uses something like html2canvas to obtain a screenshot from within Javascript, and then pass that as an input to your native extension. The JS file provided with the extension is executed in the context of the Safari page.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195