I am developing safari browser extension which should have taking screenshot functionality.
Chrome and Firefox has their own apis to take SS of the current window document. I could not find any safari specific/API documentation for it. The Windows and Tabs API
What would be the best way to achieve it?
SafariBrowserTab
has a visibleContentsAsDataURL
method to get the image data of the currently visible content.
For example, in your global page:
safari.application.addEventListener('command', performCommand, false);
// Perform e.g. when toolbar button is clicked
function performCommand(event) {
if (event.command === 'captureTab') {
var tab = safari.application.activeBrowserWindow.activeTab;
tab.visibleContentsAsDataURL(function(imgdata) {
//console.log(imgdata);
// Do something...
// e.g. Send to an injected script to display image on page:
tab.page.dispatchMessage('imgData', imgdata);
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With