-
Notifications
You must be signed in to change notification settings - Fork 10
ScreenSnippet API
See ScreenSnippet API on Confluence for more information.
The ScreenSnippet API is used to capture a snippet of their desktop (unconstrained by the host application window) and highlight portions of this snippet so it can then be consumed by the host application. This functionality is similar to the Windows Screen Snippet tool when used in rectangle capture mode. This lets a user captures portions of the Windows Desktop, highlight aspects of the image and then save this image for sharing.
The initial implementation of the ScreenSnippet API uses html2canvas across all platforms. html2canvas is a client-side JavaScript script.
This script [html2canvas] allows you to take "screenshots" of webpages or parts of it, directly on the users browser. The screenshot is based on the DOM and as such may not be 100% accurate to the real representation as it does not make an actual screenshot, but builds the screenshot based on the information available on the page.
The Electron API now uses win.capturePage and the OpenFin API now uses window.getSnapshot. Currently, internally, OpenFin's window.getSnapshot uses win.capturePage, so the functionality is very similar - only the content within the current host window is captured.
The capture() method returns a promise which resolves to a base64-encoded PNG Data URI string with contains the captured image. For example:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAADElEQVQImWNgoBMAAABpAAFEI8ARAAAAAElFTkSuQmCC
The initial implementation only captures the content within the current host window; it does not allow the content of multiple windows, or content outside of the host application to be captured. html2canvas's limitations include:
- inability to read content (styles/scripts/images) from a different origin, without a proxy
- inability to capture
<canvas>and<iframe>elements - inability to capture content from Java or Flash plugins
Electron has desktopCapturer, which supports various sources, included windows and screens (allowing content outside the bounds of the application to be captured). However, due to the requirement of enabling the sandbox in Electron's BrowserWindow, this API is unavailable.
Electron also has win.capturePage. This does not retrieve content outside the bounds of the window, but may be an alternative to using html2canvas.
OpenFin has window.getSnapshot, which gets a base64 encoded PNG snapshot of the window. This does not retrieve content outside the bounds of the window, but may be an alternative to using html2canvas.