Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari Extension Taking Screenshot

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?

like image 892
Teoman shipahi Avatar asked Aug 14 '14 22:08

Teoman shipahi


1 Answers

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);
        });
    }
}
like image 103
Matt Swain Avatar answered Feb 22 '23 04:02

Matt Swain