Safari Extension Taking Screenshot

旧巷老猫 提交于 2019-12-06 02:49:41

问题


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:


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);
        });
    }
}


来源:https://stackoverflow.com/questions/25318263/safari-extension-taking-screenshot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!