Safari Extension Taking Screenshot

2019-04-08 21:01发布

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?

1条回答
疯言疯语
2楼-- · 2019-04-08 21:46

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);
        });
    }
}
查看更多
登录 后发表回答