Skip to main content
Use this API to listen for when the user takes a screenshot. This can be used to show sharing prompts or track screenshot events.

Parameters

PropertyTypeRequiredDescription
callbackFunctionYesCallback function when user takes a screenshot

Code Example

Basic Usage

my.onUserCaptureScreen(() => {
  console.log('User took a screenshot');
});

Show Share Prompt

Page({
  onLoad() {
    my.onUserCaptureScreen(() => {
      my.confirm({
        title: 'Screenshot Captured',
        content: 'Would you like to share this screenshot?',
        confirmButtonText: 'Share',
        cancelButtonText: 'Cancel',
        success: (res) => {
          if (res.confirm) {
            my.showSharePanel();
          }
        }
      });
    });
  },

  onUnload() {
    my.offUserCaptureScreen();
  }
});

Track Screenshot Events

App({
  onLaunch() {
    my.onUserCaptureScreen(() => {
      // Log screenshot event for analytics
      this.logEvent('screenshot_taken', {
        page: getCurrentPages().pop()?.route,
        timestamp: Date.now()
      });
    });
  },

  logEvent(name, data) {
    my.request({
      url: 'https://api.example.com/analytics',
      method: 'POST',
      data: { event: name, ...data }
    });
  }
});

Sensitive Content Warning

Page({
  onLoad() {
    if (this.data.containsSensitiveInfo) {
      my.onUserCaptureScreen(() => {
        my.alert({
          title: 'Privacy Notice',
          content: 'This page contains sensitive information. Please be careful when sharing screenshots.'
        });
      });
    }
  },

  onUnload() {
    my.offUserCaptureScreen();
  }
});
Use this API to provide helpful sharing options or remind users about sensitive content when they take screenshots.

my.offUserCaptureScreen

Stop listening for screenshots

my.showSharePanel

Show share panel