我正在开发 Safari 浏览器扩展,它应该具有截图功能。
Chrome 和 Firefox 有自己的 api 来获取当前窗口文档的 SS。
我找不到任何特定于 Safari 的/API 文档。窗口和选项卡 API https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html#//apple_ref/doc/uid/TP40009977-CH17-SW1
实现这一目标的最佳方法是什么?
SafariBrowserTab
has a visibleContentsAsDataURL https://developer.apple.com/library/safari/documentation/UserExperience/Reference/SBrowserTabClassReference/index.html#//apple_ref/javascript/instm/SafariBrowserTab/visibleContentsAsDataURL方法获取当前可见内容的图像数据。
例如,在您的全局页面中:
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);
});
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)