Safari Extension Screenshot

I am developing a safari browser extension that should have a screenshot function.

Chrome and Firefox have their own apis to take the SS of the current window document. I could not find any safari specification / API documentation for it. Windows API and tabs

What would be the best way to achieve this?

+4
source share
1 answer

SafariBrowserTabhas a method visibleContentsAsDataURLfor obtaining image data of the current visible content.

For example, on 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);
        });
    }
}
+8
source

All Articles