takescreenshot:// is fire-and-forget. The native runtime captures the visible WebView contents, writes the result to the device photo gallery, and returns immediately. The user sees the standard system save confirmation. There are no parameters and no return value.
This feature captures the WebView only, not the system chrome around it (status bar, home indicator, navigation bar). For a full-screen capture including system UI, the user can trigger the OS-level screenshot shortcut on their device.
Installation
- Bundle
- CDN
How it works
Calldespia('takescreenshot://'). The OS handles the photo permission prompt the first time the app saves an image, and subsequent calls go through silently as long as the user granted access.
Capture from a button
The natural pattern is a “Save screenshot” button in the UI. Tap, capture, OS shows the system save confirmation.requestAnimationFrame is what addresses the React optimization caveat at the top of this page. Hiding the button via state takes one frame to commit to the DOM, and the screenshot needs to fire on the following frame to capture the state without the button. A single requestAnimationFrame schedules the callback for the next paint, the second one runs after that paint completes, so by the time the SDK call fires the button is genuinely off-screen.
Capture a specific element instead of the whole view
The native scheme always captures the entire WebView. To capture only one element (a card, a chart, a quote section), the practical workaround is to scroll that element into view, hide everything around it visually (overlay ordisplay: none), call takescreenshot://, then restore the original layout.
Resources
NPM Package
despia-native