Screenshot of contents of Safari from share extension

200 views Asked by At

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 ?

1

There are 1 answers

0
Léo Natan On

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.