tencent cloud

Feedback

Fundamentals

Last updated: 2024-07-12 19:39:04

    canIUse

    This API is used via Boolean wx.canIUse(string schema).
    Feature Description: Determines whether the API, callbacks, parameters, components, etc., of the mini program are usable in the current version.
    Parameter and Description: String schema:
    Invoke using the ${API}.${method}.${param}.${options} or ${component}.${attribute}.${option} method.
    Description:
    Value
    Description
    ${API}
    Represents the API name.
    ${method}
    Represents the invocation method, with valid values being return, success, object, callback.
    ${param}
    Represents parameters or return values.
    ${options}
    Represents the optional values of the parameters.
    ${component}
    Represents the component name.
    ${attribute}
    Represents the component attribute.
    ${option}
    Represents the optional values of the component attribute.
    Return Value: Boolean, indicating whether the current version is available.
    Sample Code
    wx.canIUse('openBluetoothAdapter')
    wx.canIUse('getSystemInfoSync.return.screenWidth')
    wx.canIUse('getSystemInfo.success.screenWidth')
    wx.canIUse('showToast.object.image')
    wx.canIUse('onCompassChange.callback.direction')
    wx.canIUse('request.object.method.GET')
    
    wx.canIUse('live-player')
    wx.canIUse('text.selectable')
    wx.canIUse('button.open-type.contact')

    env

    This API is used via wx.env.
    Feature Description: Environment variable.
    Parameter and Description: string USER_DATA_PATH, the user directory path in the file system (local path).

    base64ToArrayBuffer

    This API is used via ArrayBuffer wx.base64ToArrayBuffer(string base64).
    Feature Description: Converts a Base64 string into an ArrayBuffer object.
    Parameter and Description: string base64, the Base64 string to be converted into an ArrayBuffer object.
    Return Value: ArrayBuffer, an ArrayBuffer object.
    Sample Code
    const base64 = 'CxYh'
    const arrayBuffer = wx.base64ToArrayBuffer(base64)

    arrayBufferToBase64

    This API is used via string wx.arrayBufferToBase64(ArrayBuffer arrayBuffer).
    Feature Description: Converts an ArrayBuffer object into a Base64 string.
    Parameter and Description: ArrayBuffer, the ArrayBuffer object to be converted into a Base64 string.
    Return Value: string, a Base64 string.
    Sample Code
    const arrayBuffer = new Uint8Array([11, 22, 33])
    const base64 = wx.arrayBufferToBase64(arrayBuffer)

    System

    getSystemInfo

    This API is used via wx.getSystemInfo(Object object).
    Feature Description: Gets system information.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    Function
    -
    No
    Callback Function of Successful Interface Call
    fail
    Function
    -
    No
    Callback Function of Failing Interface Call
    complete
    Function
    -
    No
    Callback function executed upon the completion of the interface invocation (regardless of success or failure of the invocation)
    Callback result of Object.success's res
    Attribute
    Type
    Description
    brand
    String
    Device Brand
    Device Model
    String
    Device Model
    pixelRatio
    Number
    Device Pixel Ratio
    screenWidth
    Number
    Screen width, measured in pixels (px)
    screenHeight
    Number
    Screen height, measured in pixels (px)
    windowWidth
    Number
    Usable window width, measured in pixels (px)
    windowHeight
    Number
    Usable window height, measured in pixels (px)
    statusBarHeight
    Number
    Status bar height, measured in pixels (px)
    language
    String
    Language
    version
    String
    Version No.
    system
    String
    Operating System and Version
    platform
    String
    User font size in px
    SDKVersion
    String
    Client Base Library Version
    App Platform
    String
    App Platform
    safeArea
    Object
    Safe area in the upright orientation
    theme
    String
    The current system theme, values can be either light or dark. It can only be obtained when the global configuration "darkmode" is set to "true". Otherwise, it is undefined.
    Structure of res.safeArea:
    Attribute
    Type
    Description
    left
    Number
    Horizontal coordinate of the top left corner of the safe area
    right
    Number
    Horizontal coordinate of the bottom right corner of the safe area
    top
    Number
    Vertical coordinate of the top left corner of the safe area
    bottom
    Number
    Vertical coordinate of the bottom right corner of the safe area
    width
    Number
    Width of the safe area, measured in logical pixels
    height
    Number
    Height of the safe area, measured in logical pixels
    Sample Code
    wx.getSystemInfo({
    success(res) {
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
    }
    })
    try {
    const res = wx.getSystemInfoSync()
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
    } catch (e) {
    // Do something when catch error
    }

    getSystemInfoSync

    This API is used via Object wx.getSystemInfo().
    Feature Description: Synced version of wx.getSystemInfo.
    Callback result of Object.success's res
    Attribute
    Type
    Description
    brand
    String
    Device Brand
    Device Model
    String
    Device Model
    pixelRatio
    Number
    Device Pixel Ratio
    screenWidth
    Number
    Screen width, measured in pixels (px)
    screenHeight
    Number
    Screen height, measured in pixels (px)
    windowWidth
    Number
    Usable window width, measured in pixels (px)
    windowHeight
    Number
    Usable window height, measured in pixels (px)
    statusBarHeight
    Number
    Status bar height, measured in pixels (px)
    language
    String
    Language
    version
    String
    Version No.
    system
    String
    Operating System and Version
    platform
    String
    Client platform, with the following valid values:
    ios: iOS client (including iPhone, iPad)
    Android: Android client
    devtools: TCMPP Developer Tools
    App Platform
    String
    App Platform
    safeArea
    Object
    Safe area in the upright orientation
    theme
    String
    The current system theme, values can be either light or dark. It can only be obtained when the global configuration "darkmode" is set to "true". Otherwise, it is undefined.
    Structure of res.safeArea:
    Attribute
    Type
    Description
    left
    Number
    Horizontal coordinate of the top left corner of the safe area
    right
    Number
    Horizontal coordinate of the bottom right corner of the safe area
    top
    Number
    Vertical coordinate of the top left corner of the safe area
    bottom
    Number
    Vertical coordinate of the bottom right corner of the safe area
    width
    Number
    Width of the safe area, measured in logical pixels
    height
    Number
    Height of the safe area, measured in logical pixels
    Sample Code
    wx.getSystemInfo({
    success(res) {
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
    }
    })
    try {
    const res = wx.getSystemInfoSync()
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
    } catch (e) {
    // Do something when catch error
    }

    getSystemInfoAsync

    This API is used via wx.getSystemInfoAsync(Object object).
    Feature Description: Asynchronously gets system information. It requires support from a certain host client version. On unsupported clients, a synchronous implementation will be used for the return.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    brand
    string
    Device Brand
    Device Model
    string
    Device model. Newly launched models will display 'unknown' for a period of time. We will complete adaptation as quickly as possible.
    pixelRatio
    number
    Device Pixel Ratio
    screenWidth
    number
    Screen width, measured in pixels (px)
    screenHeight
    number
    Screen height, measured in pixels (px)
    windowWidth
    number
    Usable window width, measured in pixels (px)
    windowHeight
    number
    Usable window height, measured in pixels (px)
    statusBarHeight
    number
    Task status bar height, measured in pixels (px)
    language
    string
    Language settings within the application.
    version
    string
    Application Version No.
    system
    string
    Operating System and Version
    platform
    string
    Client platform, with the following valid values:
    ios: iOS client (including iPhone, iPad)
    Android: Android client
    devtools: IDE Developer Tools
    fontSizeSetting
    number
    User font size, measured in pixels (px).
    SDKVersion
    string
    Client Base Library Version
    safeArea
    object
    Safe area in the upright orientation of the screen. Some models do not have the concept of a safe area and will not return the 'safeArea' field, requiring developers to ensure compatibility. See the table below: Return Values of 'safeArea'.
    locationReducedAccuracy
    boolean
    "True" signifies approximate location, while "false" indicates precise location, supported exclusively on iOS.
    theme
    string
    The current system theme can only be obtained when the global configuration 'darkmode' is set to "true". Otherwise, it will be undefined. The valid values are:
    Light
    Dark
    Return value of safeArea
    Structure attributes
    Type
    Description
    left
    number
    Horizontal coordinate of the top left corner of the safe area
    right
    number
    Horizontal coordinate of the bottom right corner of the safe area
    top
    number
    Vertical coordinate of the top left corner of the safe area
    bottom
    number
    Vertical coordinate of the bottom right corner of the safe area
    width
    number
    Width of the safe area, measured in logical pixels
    height
    number
    Height of the safe area, measured in logical pixels
    Sample Code
    wx.getSystemInfoAsync({
    success(res) {
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
    }
    })

    getWindowInfo

    The usage method of this API is Object wx.getWindowInfo()
    Feature Description: Gets window information.
    Parameter and Description: Object.
    Attribute
    Type
    Description
    pixelRatio
    number
    Device Pixel Ratio
    screenWidth
    number
    Screen width, measured in pixels (px)
    screenHeight
    number
    Screen height, measured in pixels (px)
    windowWidth
    number
    Usable window width, measured in pixels (px)
    windowHeight
    number
    Usable window height, measured in pixels (px)
    statusBarHeight
    number
    Status bar height, measured in pixels (px)
    safeArea
    object
    Safe area in the upright orientation of the screen. Some models do not have the concept of a safe area and will not return the 'safeArea' field, requiring developers to ensure compatibility.
    screenTop
    number
    The y-value of the window's upper edge
    Return value of safeArea
    Structure attributes
    Type
    Description
    left
    number
    Horizontal coordinate of the top left corner of the safe area
    right
    number
    Horizontal coordinate of the bottom right corner of the safe area
    top
    number
    Vertical coordinate of the top left corner of the safe area
    bottom
    number
    Vertical coordinate of the bottom right corner of the safe area
    width
    number
    Width of the safe area, measured in logical pixels
    height
    number
    Height of the safe area, measured in logical pixels
    Sample Code
    const windowInfo = wx.getWindowInfo()
    
    console.log(windowInfo.pixelRatio)
    console.log(windowInfo.screenWidth)
    console.log(windowInfo.screenHeight)
    console.log(windowInfo.windowWidth)
    console.log(windowInfo.windowHeight)
    console.log(windowInfo.statusBarHeight)
    console.log(windowInfo.safeArea)
    console.log(windowInfo.screenTop)

    getSystemSetting

    The usage method of this API is Object wx.getSystemSetting()
    Feature Description: Gets device settings.
    Parameter and Description: Object.
    Attribute
    Type
    Description
    bluetoothEnabled
    boolean
    System toggle for Bluetooth functionality.
    locationEnabled
    boolean
    System toggle for geographical location functionality.
    wifiEnabled
    boolean
    System toggle for Wi-Fi functionality.
    deviceOrientation
    string
    Device orientation, whose valid values are:
    Portrait: Vertical Screen
    Landscape: Horizontal Screen
    Sample Code
    const systemSetting = wx.getSystemSetting()
    
    console.log(systemSetting.bluetoothEnabled)
    console.log(systemSetting.deviceOrientation)
    console.log(systemSetting.locationEnabled)
    console.log(systemSetting.wifiEnabled)

    openSystemBluetoothSetting

    The usage method of this API is wx.openSystemBluetoothSetting(Object object)
    Feature Description: Redirects to the system's Bluetooth settings page. Only supported on Android.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.openSystemBluetoothSetting({
    success(res) {
    console.log(res)
    }
    })

    openAppAuthorizeSetting

    The usage method of this API is wx.openAppAuthorizeSetting(Object object).
    Feature Description: Redirects to the system host client's authorization management page.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.openAppAuthorizeSetting({
    success(res) {
    console.log(res)
    }
    })

    getRendererUserAgent

    The usage method of this API is Promise wx.getRendererUserAgent(Object object).
    Feature Description: Gets the UserAgent of the Webview mini program.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: string userAgent, UserAgent.
    Return Value: Promise.<string>
    Sample Code
    wx.getRendererUserAgent().then(userAgent => console.log(userAgent))
    wx.getRendererUserAgent({
    success(res) {
    console.log(res.userAgent)
    }
    })

    getDeviceInfo

    The usage method of this API is Object wx.getDeviceInfo()
    Feature Description: Gets the fundamental information of the device.
    Return Value: Object.
    Attribute
    Type
    Description
    abi
    string
    Host App's binary interface type (supported only on Android)
    deviceAbi
    string
    Device's binary interface type (supported only on Android)
    benchmarkLevel
    number
    Device performance level (supported on Android only). Valid values include:
    -2 or 0: This device is incapable of running mini games.
    -1: Performance unknown.
    >=1: Device performance value (currently not exceeding 50). The higher the value, the better the device performance.
    brand
    string
    Device Brand
    Device Model
    string
    Device model. Newly launched models will display 'unknown' for a period of time. We will complete adaptation as quickly as possible.
    system
    string
    Operating System and Version
    platform
    string
    Client platform
    cpuType
    string
    Device CPU model (supported only on Android) GPU model can be obtained through WebGLRenderingContext.getExtension('WEBGL_debug_renderer_info')
    menorySize
    string
    Device memory size, measured in MB.
    Sample Code
    const deviceInfo = wx.getDeviceInfo()
    
    console.log(deviceInfo.abi)
    console.log(deviceInfo.benchmarkLevel)
    console.log(deviceInfo.brand)
    console.log(deviceInfo.model)
    console.log(deviceInfo.platform)
    console.log(deviceInfo.system)

    getAppBaseInfo

    This API is used via Object wx.getAppBaseInfo().
    Feature Description: Gets basic information of the host client.
    Parameter and Description: Object.
    Attribute
    Type
    Description
    SDKVersion
    string
    Host client's base library version
    enableDebug
    boolean
    Whether debugging has been activated. Debugging can be enabled through the menu in the top right corner or via wx.setEnableDebug.
    host
    Object
    The host environment in which the current mini program is running.
    The structure attribute is a string type appId, used for the corresponding appId of the host client (third-party App), which is returned only when the mini program is running in a third-party App environment.
    language
    string
    The language set by the host client.
    version
    string
    Host client version number
    theme
    string
    The current system theme has a value of either "light" (bright mode) or "dark" (dark mode). It can only be obtained when the global configuration "darkmode" is set to "true". Otherwise, it is undefined. (Not supported in mini games)
    Sample Code
    const appBaseInfo = wx.getAppBaseInfo()
    
    console.log(appBaseInfo.SDKVersion)
    console.log(appBaseInfo.enableDebug)
    console.log(appBaseInfo.host)
    console.log(appBaseInfo.language)
    console.log(appBaseInfo.version)
    console.log(appBaseInfo.theme)

    getAppAuthorizeSetting

    The usage method of this API is Object wx.getAppAuthorizeSetting().
    Feature Description: Gets the authorization settings of the host client.
    Parameter and Description: Object.
    Attribute
    Type
    Description
    albumAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client to access the album (effective on iOS only).
    bluetoothAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client to use the Bluetooth (effective on iOS only).
    cameraAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client to use the camera.
    locationAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client to use location services.
    locationReducedAccuracy
    boolean
    "True" signifies approximate location, while "false" indicates precise location, supported exclusively on iOS.
    microphoneAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client to use the microphone.
    notificationAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client notifications.
    notificationAlertAuthorized
    'authorized'/'denied'/'not determined'
    Permission host toggle for client notifications to carry a reminder (effective on iOS only).
    notificationBadgeAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client notifications to carry a marker (effective on iOS only).
    notificationSoundAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client notifications to have sound (effective on iOS only).
    phoneCalendarAuthorized
    'authorized'/'denied'/'not determined'
    Permission toggle for host client to read and write the calendar.
    Sample Code
    const appAuthorizeSetting = wx.getAppAuthorizeSetting()
    
    console.log(appAuthorizeSetting.albumAuthorized)
    console.log(appAuthorizeSetting.bluetoothAuthorized)
    console.log(appAuthorizeSetting.cameraAuthorized)
    console.log(appAuthorizeSetting.locationAuthorized)
    console.log(appAuthorizeSetting.locationReducedAccuracy)
    console.log(appAuthorizeSetting.microphoneAuthorized)
    console.log(appAuthorizeSetting.notificationAlertAuthorized)
    console.log(appAuthorizeSetting.notificationAuthorized)
    console.log(appAuthorizeSetting.notificationBadgeAuthorized)
    console.log(appAuthorizeSetting.notificationSoundAuthorized)
    console.log(appAuthorizeSetting.phoneCalendarAuthorized)

    Update

    getUpdateManager

    This API is used via UpdateManager wx.getUpdateManager.
    Feature Description: Gets the globally unique version update manager, used for managing mini program updates, with the usage method being UpdateManager wx.getUpdateManager.
    Return Value: UpdateManager, the update manager object.

    UpdateManager

    .applyUpdate

    This method is used via UpdateManager.applyUpdate().
    Feature Description: Forces the mini program to restart and use the new version. This is invoked after the new version of the mini program has been downloaded (i.e., upon receipt of the onUpdateReady callback).

    .onCheckForUpdate

    This method is used via UpdateManager.onCheckForUpdate(function listener).
    Feature Description: Monitors events of requesting the backend to check for update results. The mini program automatically checks for updates during a cold start, eliminating the need for the developer to manually trigger it.
    Parameter and Description: function callback, the callback function for the event of requesting the backend to check for update results.
    Attribute
    Type
    Description
    hasUpdate
    Boolean
    Is there a new version?

    .onUpdateFailed

    This method is used via UpdateManager.onUpdateFailed(function listener).
    Feature Description: Monitors events of a version update for the mini program. The client initiates the download (no developer trigger required), and a callback is executed upon successful download.
    Parameter and Description: function callback, the callback function for the event of a mini program update failure.

    .onUpdateReady

    This method is used via UpdateManager.onUpdateReady(function listener).
    Feature Description: Monitors events of a mini program update failure. When a new version of the mini program is available, the client initiates the download (no developer trigger required), and a callback is executed if the download fails (possibly due to network issues, etc.).
    Parameter and Description: function callback, the callback function for the event of a new version update for the mini program.
    Sample Code
    const updateManager = wx.getUpdateManager()
    
    updateManager.onCheckForUpdate(function (res) {
    // Callback after the new version information request is completed
    console.log(res.hasUpdate)
    })
    
    updateManager.onUpdateReady(function () {
    wx.showModal({
    title: 'Update Prompt',
    content: 'The new version is ready. Would you like to restart the application?'
    success(res) {
    if (res.confirm) {
    // The new version has been downloaded. Call applyUpdate to apply the new version and restart.
    updateManager.applyUpdate()
    }
    }
    })
    })
    
    updateManager.onUpdateFailed(function () {
    // New version download failed.
    })

    Mini Program

    Lifecycle

    getLaunchOptionsSync

    The usage method of this API is Object wx.getLaunchOptionsSync().
    Note:
    Some versions will return undefined when there is no referrerInfo, it is recommended to use options.referrerInfo && options.referrerInfo.appId to judge.
    Feature Description: Gets the parameters at the launch of the mini program.
    Return Value: Object, launch parameters.
    Attribute
    Type
    Description
    path
    String
    The path to launch the mini program.
    scene
    Number
    Scenario value for launching the mini program, default is 1001
    query
    Object
    The query parameters for launching the Mini Program.
    referrerInfo
    Object
    Source information, returned when entering the mini program from another mini program or App. Otherwise returns {}
    forwardMaterials
    Array.<Object>
    An array of information about the opened file, which is only carried if it is opened from a chat clip scene
    The structure of referrerInfo.
    Attribute
    Type
    Description
    appId
    String
    The appId of the source mini program or app.
    extraData
    Object
    Data passed by the source mini program
    The structure of forwardMaterials.
    Attribute
    Type
    Description
    type
    string
    The mimetype type of the file.
    name
    Object
    File Name
    path
    string
    File path
    size
    number
    File size
    Scenes where valid referrerInfo is returned.
    Attribute
    Type
    Significance of appId
    1036
    App message sharing card
    Originating from App
    1037
    Open a mini program from another mini program
    Originating from mini program
    1038
    Returning from another mini program
    Originating from mini program

    getEnterOptionsSync

    This API is used via Object wx.getEnterOptionsSync().
    Note:
    Some versions will return undefined when there is no referrerInfo, it is recommended to use options.referrerInfo && options.referrerInfo.appId to judge.
    Feature Description: Gets the parameters at the time of this mini program's initiation. If it is a cold start, the return value is consistent with the callback parameters of App.onLaunch; if it is a hot start, the return value is consistent with App.onShow.
    Return Value: Object
    Attribute
    Type
    Description
    path
    string
    Path to launch the mini program (code package path)
    scene
    number
    Scenario values for launching a mini program
    query
    Object
    The query parameters for launching the Mini Program.
    shareTicket
    string
    shareTicket
    referrInfo
    Object
    Source information. The value is returned when entering the mini program from another mini program, We Chat Official Account, or App. Otherwise, it returns {}. For specifics, see the notes preceding the table.
    forwardMaterials
    Array.<Object>
    Array of opened file information, a parameter that is only carried when opened from the chat material scene (scene is 1173).
    chatType
    number
    When opening the mini program from a group chat or private chat in the host client, chatType indicates the specific type of group chat or private chat within the host client. The valid values are:
    1: Single chat with host client contacts
    2: Single chat with corporate host client contacts
    3: Common host client group chat
    4: Intercommunication group chat in corporate host client
    The structure of referrerInfo.
    Attribute
    Type
    Description
    appId
    String
    The appId of the source mini program or app.
    extraData
    Object
    Data passed by the source mini program
    The structure of forwardMaterials.
    Attribute
    Type
    Description
    type
    String
    The mimetype type of the file.
    name
    Object
    File Name
    path
    String
    File path (or URL if it's a webview)
    size
    Number
    File size
    Scenarios returning valid referrerInfo
    Attribute
    Type
    Significance of appId
    1036
    App message sharing card
    Originating from App
    1037
    Open a mini program from another mini program
    Originating from mini program
    1038
    Returning from another mini program
    Originating from mini program

    Application-level events

    onError

    The usage method of this API is wx.onError(function callback)
    Feature Description: Monitors errors within the mini program, such as script errors or API call failures.
    Parameter and Description: function callback, the callback function for mini program error events.
    Return Parameter: string error, error information, including the stack.

    offError

    The usage method of this API is wx.offError(function callback)
    Feature Description: Cancels the monitoring of mini program error events.
    Parameter and Description: function callback, the callback function for mini program error events.

    onThemeChange

    The usage method of this API is wx.onThemeChange(function listener)
    Note:
    This event will only be triggered when the global configuration darkmode is set to "true".
    Feature Description: Monitors system theme change events.
    Parameter and Description: function listener, the monitoring function for system theme change events.
    Return Parameter: Object res
    Attribute
    Valid Values and Descriptions
    Type
    Description
    theme
    Dark: Dark Theme
    Light: Light Theme
    String
    The current theme of the system, either light or dark.

    offThemeChange

    The usage method of this API is wx.offThemeChange(function listener).
    Function Description: Removes the listener function for system theme change events.
    Parameter and Description: Function listener, the listener function passed in by onThemeChange. If this parameter is not provided, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    wx.onThemeChange(listener)
    wx.offThemeChange(listener) // The same function object as the listener must be passed in.

    onPageNotFound

    The usage method of this API is wx.onPageNotFound(function listener).
    Note:
    Developers can redirect the page within the callback, but it must be handled synchronously within the callback. Asynchronous handling (such as asynchronous execution with setTimeout) is invalid.
    If the developer does not call wx.onPageNotFound to bind the listener, and does not declare App.onPageNotFound, when the page to be redirected does not exist, it will push into the host client's native page-not-found prompt page.
    If the callback redirects to another non-existent page, it will push into the host client's native page-not-found prompt page, without callback for a second time.
    Feature Description: Monitors events where the page that the mini program wants to open does not exist. The timing of this event is consistent with the callback of App.onPageNotFound.
    Parameter and Description: Object res parameter, function listener, which is the listener function for events where the page that the mini program wants to open does not exist.
    Attribute
    Type
    Description
    path
    string
    Path of the non-existent page (code package path)
    query
    Object
    Query parameters for opening a non-existent page
    isEntryPage
    boolean
    Whether it is the first page of this launch (for example, when entering from shares or other entrances, the first page is the share page configured by the developer)

    offPageNotFound

    The usage method of this API is wx.offPageNotFound(function listener).
    Feature Description: Removes the listener function for events where the page that the mini program wants to open does not exist.
    Parameter and Description: function listener, the listener function passed in by onPageNotFound. If this parameter is not passed, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    wx.onPageNotFound(listener)
    wx.offPageNotFound(listener) // The same function object as the listener must be passed in.

    onAppShow

    The usage method of this API is wx.onAppShow(function listener)
    Note:
    Some versions will return undefined if there is no referrerInfo, it is recommended to use options.referrerInfo && options.referrerInfo.appId to judge.
    Feature Description: Monitors events of mini program switching to the frontend. The callback parameters of these events are consistent with those of App.onShow.
    Parameter and Description: Object res parameter, function listener, the listener function for events of mini program switching to the frontend.
    Attribute
    Type
    Description
    path
    string
    Path to launch the mini program (code package path)
    scene
    number
    Scenario values for launching a mini program
    query
    Object
    The query parameters for launching the Mini Program.
    shareTicket
    string
    shareTicket
    referrerInfo
    Object
    Source information. Returned when the mini programme is accessed from another mini program or an App. Otherwise returns {}, see the note in the previous section of the form.
    forwardMaterials
    Array.<Object>
    An array of information about the opened file, which is only carried if it is opened from a chat clip scene
    chatType
    number
    When opening the mini program from a group chat or private chat in the host client, chatType indicates the specific type of group chat or private chat within the host client. The valid values are:
    1: Single chat contacts within the host client
    2: Single chat with corporate contacts within the host client
    3: Common group chat within the host client
    4: Inter-company group chat within the host client
    The structure of referrerInfo.
    Attribute
    Type
    Description
    appId
    string
    The appId of the source mini program or app.
    extraData
    Object
    Data passed by the source mini program
    The structure of forwardMaterials.
    Attribute
    Type
    Description
    type
    String
    The mimetype type of the file.
    name
    Object
    File Name
    path
    String
    File path (or URL if it's a webview)
    size
    Number
    File size
    Scenarios returning valid referrerInfo
    Scene Value
    Scene
    Significance of appId
    1036
    App message sharing card
    Originating from App
    1037
    Open a mini program from another mini program
    Originating from mini program
    1038
    Returning from another mini program
    Originating from mini program

    offAppShow

    The usage method of this API is wx.offAppShow(function listener).
    Feature Description: Removes the liThestener function for events of mini program switch to frontend.
    Parameter and Description: function listener, the listener function passed in by onAppShow. If this parameter is not passed, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    wx.onAppShow(listener)
    wx.offAppShow(listener) // The same function object as the listener must be passed in.

    onAppHide

    The usage method of this API is wx.onAppHide(function listener).
    Feature Description: Monitors events of mini program switching to the backend. The timing of this event is consistent with the callback of App.onHide.
    Parameter and Description: function listener, the listener function for events of mini program switching to the backend.

    offAppHide

    The usage method of this API is wx.offAppHide(function listener)
    Feature Description: Removes the listener function for events of mini program switch to frontend.
    Parameter and Description: function listener, the listener function passed in by onAppHide. If this parameter is not passed, all listener functions will be removed.
    const listener = function (res) { console.log(res) }
    
    wx.onAppHide(listener)
    wx.offAppHide(listener) // The same function object as the listener must be passed in.

    onUnhandledRejection

    The usage method of this API is wx.onUnhandledRejection(function listener).
    Note:
    All unhandledRejection events can be captured by this listener, but only those of the Error type will trigger an alarm in the mini program backend.
    Feature Description: Monitors unhandled Promise rejection events.
    Parameter and Description: Object res parameter, function listener, the listener function for unhandled Promise rejection events.
    Attribute
    Type
    Description
    reason
    string
    Rejection reason, typically an Error object.
    promise
    Promise.<any>
    The rejected Promise object.

    offUnhandledRejection

    The usage method of this API is wx.offUnhandledRejection(function listener).
    Feature Description: Removes the listener function for unhandled Promise rejection events.
    Parameter and Description: Function listener, the listener function passed in by onUnhandledRejection. If this parameter is not provided, all listener functions will be removed.
    Sample Code
    const listener = function (res) { console.log(res) }
    
    wx.onUnhandledRejection(listener)
    wx.offUnhandledRejection(listener) // The same function object as the listener must be passed in.

    Debug

    setEnableDebug

    The usage method of this API is wx.setEnableDebug(Object object).
    Feature Description: Sets whether to enable the debugging switch. This switch is also effective for the official version.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    enableDebug
    boolean
    -
    Yes
    Whether to enable debugging
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    // Enable debugging
    wx.setEnableDebug({
    enableDebug: true
    })
    
    // Disable debugging
    wx.setEnableDebug({
    enableDebug: false
    })
    Note:
    Open debugging in the official version can also open debugging in the development version or experience version first, and then cut to the official version to see the vConsole.

    getRealtimeLogManager

    This API is used via RealtimeLogManager wx.getRealtimeLogManager().
    Feature Description: Gets the real-time log manager object.
    Return Value: RealtimeLogManager.
    Sample Code
    // Mini Program End
    const logger = wx.getRealtimeLogManager()
    logger.info({str: 'hello world'}, 'info log', 100, [1, 2, 3])
    logger.error({str: 'hello world'}, 'error log', 100, [1, 2, 3])
    logger.warn({str: 'hello world'}, 'warn log', 100, [1, 2, 3])
    
    // Plugin end, supported after the 2.16.0 base library version, only allows reporting in the new key-value format.
    const logManager = wx.getRealtimeLogManager()
    const logger = logManager.tag('plugin-log1')
    logger.info('key1', 'value1')
    logger.error('key2', {str: 'value2'})
    logger.warn('key3', 'value3')

    getLogManager

    This API is used via LogManager wx.getLogManager(Object object).
    Feature Description: Gets the log manager object.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    level
    number
    0
    No
    The value is 0/1, where 0 indicates whether the lifecycle functions of App and Page and function calls under the namespace, will be written into the log. A value of 1 means they will not be. The default value is 0.
    Return Value: LogManager.
    Sample Code
    const logger = wx.getLogManager({level: 1})
    logger.log({str: 'hello world'}, 'basic log', 100, [1, 2, 3])
    logger.info({str: 'hello world'}, 'info log', 100, [1, 2, 3])
    logger.debug({str: 'hello world'}, 'debug log', 100, [1, 2, 3])
    logger.warn({str: 'hello world'}, 'warn log', 100, [1, 2, 3])

    console

    Console is a globally accessible object with a specific set of methods as follows. It can print logs in the IDE debugging panel and output logs in the client using vConsole.

    LogManager

    The LogManager instance can be obtained through getLogManager, with the specific set of methods outlined below.

    RealtimeLogManager

    RealtimeTagLogManager

    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support