All Products
Document Center


Last Updated: Mar 05, 2021

This interface is used for snapshot.

Use snapshot interface

  1.'snapshot', function(result) {
  2. console.log(result.success);
  3. });

Code sample

  1. <h1>Click the buttons below to see different snapshot effects</h1>
  2. <a href="javascript:void(0)" class="btn screen">Capture screen and save to the Gallery</a>
  3. <a href="javascript:void(0)" class="btn viewport">Viewport snapshot returns fileURL</a>
  4. <script>
  5. function ready(callback) {
  6. // Call directly if JSBridge has been injected
  7. if (window.AlipayJSBridge) {
  8. callback && callback();
  9. } else {
  10. // Monitor the injected events if JSBridge hasn't been injected
  11. document.addEventListener('AlipayJSBridgeReady', callback, false);
  12. }
  13. }
  14. ready(function() {
  15. document.querySelector('.screen').addEventListener('click', function() {
  16.'snapshot', function(result) {
  17. alert(JSON.stringify(result));
  18. });
  19. });
  20. document.querySelector('.viewport').addEventListener('click', function() {
  21.'snapshot', {
  22. range: 'viewport',
  23. dataType: 'fileURL',
  24. saveToGallery: false
  25. }, function(result) {
  26. alert(JSON.stringify(result));
  27. });
  28. });
  29. });
  30. </script>


  1.'snapshot', {
  2. range, saveToGallery, dataType, imageFormat, quality,
  3. maxWidth, maxHeight
  4. }, fn)

Input parameters

Name Type Description Required Default value
range String Snapshot range:
Screen: The whole screen of the current client
Viewport: Visible area in the webpage
Document: The entire webpage.
Note: document captures all webpages. On Android, the browser memory will overflow if the webpage is too large, so please use Screen
N screen
saveToGallery bool Whether or not to save to Gallery N true
dataType String Result data format:
dataURL: Base64-encoded image data
fileURL: The URL of image in the file system (the image is stored in the temporary directory and will be cleared when you quit the App)
none: No data is returned (for saving to the Gallery)
N none
imageFormat String jpg / png N “jpg”
quality int The quality of JPG image, with value from 1 to 100 N 75
maxWidth int The maximum width of image, which will be reduced by equal ratio if too large N Unlimited
maxHeight int The maximum height of image, which will be reduced by equal ratio if too large N Unlimited
fn function Callback function N

Output parameters

Parameter result brought in by the callback function: {success, fileUrl, dataURL}.

Name Type Description
success bool Whether the processing is successful
fileUrl String The URL of image in the file system
fileUrl String Base64-encoded image data

Error code

Error code Description
10 Failed to save Gallery
11 Failed to save image file