0

I am converting legacy Safari extension to Safari app extension, Here's a link

My legacy extension used safari.application.activeBrowserWindow.activeTab.visibleContentsAsDataURL function to capture screenshot of active tab, how can I do that with Safari app extension? Please help.

PhuTa
  • 59
  • 6

1 Answers1

0

Here are the steps to get the screenshot of the web page

1) send a message from the injected script to the app extension using safari.extension.disptachMessage

2) Below method in SafariExtensionHandler class will be invoked.

func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]?) 

3) screenshot can be taken using "page" parameter in the above mentioned function.

page.getScreenshotOfVisibleArea { (NSImage)

}

NSImage is the screenshot of the web page

Remember you can only get screenshot of currently visible area of the web page not the whole page.

asdfg
  • 3
  • 4