tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-04-10 18:18:33
Basic
Last updated: 2025-04-10 18:18:33

canIUse

This API is called using Boolean wx.canIUse(string schema).
Feature description:Checks whether the APIs, callbacks, parameters, and components of the mini program are supported in the current version.
Parameter and description:String schema
Use the format ${API}.${method}.${param}.${options} or ${component}.${attribute}.${option} to call.
Parameter description:
Parameter
Description
${API}
API name.
${method}
Call method. Valid values: return, success, object, callback.
${param}
Parameter or return value.
${options}
Optional values of the parameter.
${component}
Component name.
${attribute}
Component property.
${option}
Optional value of the component property.
Return value: Boolean, indicating whether the feature is available in the current version.
Example:
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 called using wx.env.
Feature description:Environment variables.
Parameter and description:string USER_DATA_PATH, the user directory path in the file system (local path).

base64ToArrayBuffer

This API is called using ArrayBuffer wx.base64ToArrayBuffer(string base64).
Note:
This API is supported in mini programs but not in mini games.
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.
Example:
const base64 = 'CxYh'
const arrayBuffer = wx.base64ToArrayBuffer(base64)

arrayBufferToBase64

This API is called using string wx.arrayBufferToBase64(ArrayBuffer arrayBuffer).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Converts an ArrayBuffer object into a Base64 string.
Parameter and description:ArrayBuffer arrayBuffer, the ArrayBuffer object to be converted into a Base64 string.
Return value:string, a Base64 string.
Example:
const arrayBuffer = new Uint8Array([11, 22, 33])
const base64 = wx.arrayBufferToBase64(arrayBuffer)

System

getSystemInfo

This API is called using wx.getUserInfo(Object object).
Feature description:Gets system information.
Parameter and description:Object Object.
Property
Type
Default value
‍Required
Description
success
Function
-
False
Callback function for successful API calls.
fail
Function
-
False
Callback function for failed API calls.
complete
Function
-
False
Callback function executed after API call ends (regardless of success or failure).
Res callback result of Object.success
Property
Type
Description
brand
String
Device brand.
model
String
Device model.
pixelRatio
Number
Device pixel ratio.
screenWidth
Number
Screen width in px.
screenHeight
Number
Screen height in px.
windowWidth
Number
Available window width in px.
windowHeight
Number
Available window height in px.
statusBarHeight
Number
Status bar height in px.
language
String
Language.
version
String
Version number.
system
String
Operating system and version.
platform
String
Client platform. Valid values:
iOS: including iPhone and iPad
Android
devtools: TCSAS developer tools
fontSizeSetting
number
User font size in px.
SDKVersion
String
Base library version of the client.
AppPlatform
String
App platform.
safeArea
Object
Safe area in portrait mode.
theme
String
Current system theme.Value: Light or dark.Only available if"darkmode":true Otherwise, it is undefined.
res.safeArea structure:
Property
Type
Description
left
Number
X-coordinate of the top-left corner of the safe area.
right
Number
X-coordinate of the bottom-right corner of the safe area.
top
Number
Y-coordinate of the top-left corner of the safe area.
bottom
Number
Y-coordinate of the bottom-right corner of the safe area.
width
Number
Width of the safe area in logical pixels.
height
Number
Height of the safe area in logical pixels.
Example:
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 called using Object wx.getSystemInfoSync().
Feature description: Synchronously performs the same feature as wx.getSystemInfo.
Res callback result of Object.success
Property
Type
Description
brand
String
Device brand.
model
String
Device model.
pixelRatio
Number
Device pixel ratio.
screenWidth
Number
Screen width in px.
screenHeight
Number
Screen height in px.
windowWidth
Number
Available window width in px.
windowHeight
Number
Available window height in px.
statusBarHeight
Number
Status bar height in px.
language
String
Language.
version
String
Version number.
system
String
Operating system and version.
platform
String
Client platform. Valid values:
iOS: including iPhone and iPad
Android
devtools: TCSAS developer tools
fontSizeSetting
number
User font size in px.
AppPlatform
String
App platform.
safeArea
Object
Safe area in portrait mode.
theme
String
Current system theme.Value: Light or dark.Only available if"darkmode":true Otherwise, it is undefined. (Not supported in mini games)
res.safeArea structure:
Property
Type
Description
left
Number
X-coordinate of the top-left corner of the safe area.
right
Number
X-coordinate of the bottom-right corner of the safe area.
top
Number
Y-coordinate of the top-left corner of the safe area.
bottom
Number
Y-coordinate of the bottom-right corner of the safe area.
width
Number
Width of the safe area in logical pixels.
height
Number
Height of the safe area in logical pixels.
Example:
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 called using wx.getSystemInfoAsync(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Asynchronously gets system information. This feature is enabled only on certain versions of host client. On unsupported clients, system information is got synchronously.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
object.success callback function parameter:Object res
Property
Type
Description
brand
string
Device brand.
model
string
Device model. New models may show as Unknown for a while until adapted.
pixelRatio
number
Device pixel ratio.
screenWidth
number
Screen width in px.
screenHeight
number
Screen height in px.
windowWidth
number
Available window width in px.
windowHeight
number
Available window height in px.
statusBarHeight
number
Task status bar height in px.
language
string
Language set in the app.
version
string
App version number.
system
string
Operating system and version.
platform
string
Client platform. Valid values:
iOS: including iPhone and iPad
Android
devtools: IDE
fontSizeSetting
number
User font size in px.
SDKVersion
string
Base library version of the client.
safeArea
object
Safe area in portrait mode. Some devices do not have a safe area concept and will not return the safeArea field. Developers need to handle this compatibility. For return values, see the table Return values of safeArea
theme
string
The current system theme. The value can only be obtained when darkmode: true is set in global configuration. Otherwise, it is undefined (not supported in mini games). Valid values:
Light: bright mode
Dark: dark mode
Return values of safeArea
Structural property
Type
Description
left
number
X-coordinate of the top-left corner of the safe area.
right
number
X-coordinate of the bottom-right corner of the safe area.
top
number
Y-coordinate of the top-left corner of the safe area.
bottom
number
Y-coordinate of the bottom-right corner of the safe area.
width
number
Width of the safe area in logical pixels.
height
number
Height of the safe area in logical pixels.
Example:
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

This API is called using Object wx.getWindowInfo().
Feature description:Gets window information.
Parameter and description:Object.
Property
Type
Description
pixelRatio
number
Device pixel ratio.
screenWidth
number
Screen width in px.
screenHeight
number
Screen height in px.
windowWidth
number
Available window width in px.
windowHeight
number
Available window height in px.
statusBarHeight
number
Status bar height in px.
safeArea
object
Safe area in portrait mode. Some devices do not have a safe area concept and will not return the safeArea field. Developers need to handle this compatibility.
screenTop
number
The y-coordinate of the top edge of the window.
Return values of safeArea
Structural property
Type
Description
left
number
X-coordinate of the top-left corner of the safe area.
right
number
X-coordinate of the bottom-right corner of the safe area.
top
number
Y-coordinate of the top-left corner of the safe area.
bottom
number
Y-coordinate of the bottom-right corner of the safe area.
width
number
Width of the safe area in logical pixels.
height
number
Height of the safe area in logical pixels.
Example:
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

This API is called using Object wx.getSystemSetting().
Note:
This API is supported in mini programs but not in mini games.
Feature description:Gets device settings.
Parameter and description:Object.
Property
Type
Description
bluetoothEnabled
boolean
Bluetooth permission.
locationEnabled
boolean
Location permission.
wifiEnabled
boolean
Wi-Fi permission.
deviceOrientation
string
Device orientation. Valid values:
Portrait: Portrait mode
Landscape: Landscape mode
Example:
const systemSetting = wx.getSystemSetting()

console.log(systemSetting.bluetoothEnabled)
console.log(systemSetting.deviceOrientation)
console.log(systemSetting.locationEnabled)
console.log(systemSetting.wifiEnabled)

openSystemBluetoothSetting

This API is called using wx.openSystemBluetoothSetting(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Redirects to the system’s Bluetooth settings page. Only supported on Android.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.openSystemBluetoothSetting({
success (res) {
console.log(res)
}
})

openAppAuthorizeSetting

This API is called using wx.openAppAuthorizeSetting(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Redirects to the system host client's authorization management page.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.openAppAuthorizeSetting({
success (res) {
console.log(res)
}
})

getRendererUserAgent

This API is called using Promise wx.getRendererUserAgent(Object object).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Gets the UserAgent of the web-view container where the mini program is running.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
object.success callback function parameter:string userAgent, UserAgent.
Return value:Promise.<string>.
Example:
wx.getRendererUserAgent().then(userAgent => console.log(userAgent))
wx.getRendererUserAgent({
success(res) {
console.log(res.userAgent)
}
})

getDeviceInfo

This API is called using Object wx.getDeviceInfo().
Feature description:Gets the basic information of the device.
Return value:Object.
Property
Type
Description
abi
string
Host app's binary interface type (Android only).
deviceAbi
string
Device’s binary interface type (Android only).
benchmarkLevel
number
Device performance level (Android only). Valid values:
-2 or 0: Mini games are not supported on the device.
-1: Performance unknown.
>=1: Device performance value (the max value is currently less than 50). The higher the value, the better the device performance.
brand
string
Device brand.
model
string
Device model. New models may show as Unknown for a while until adapted.
system
string
Operating system and version.
platform
string
Client platform.
cpuType
string
Device CPU model (supported on Android only).The GPU model can be obtained using WebGLRenderingContext.getExtension('WEBGL_debug_renderer_info').
menorySize
string
Device memory size in MB.
Example:
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 called using Object wx.getAppBaseInfo().
Feature description:Gets basic information of the host client.
Parameter and description:Object.
Property
Type
Description
SDKVersion
string
Base library version of the host client.
enableDebug
boolean
Whether debugging has been enabled. You can open the menu in the upper right corner, tap Enable debugging or using wx.setEnableDebug to enable debugging.
host
Object
The host environment where the current mini program is running.
language
string
Language set on the host client.
version
string
Host client version number.
theme
string
The current system theme. Valid values: light: Bright mode, or dark: Dark mode. The value can only be obtained when "darkmode":true is set in global configuration. Otherwise, it is undefined (not supported in mini games).
Example:
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

This API is called using Object wx.getAppAuthorizeSetting().
Feature description:Gets permission info of the host client.
Parameter and description:Object.
Property
Type
Description
albumAuthorized
'authorized'/'denied'/'not determined'
Gets the album permission info of the host client. (iOS only).
bluetoothAuthorized
'authorized'/'denied'/'not determined'
Gets the Bluetooth permission info of the host client. (iOS only).
cameraAuthorized
'authorized'/'denied'/'not determined'
Gets the camera permission info of the host client.
locationAuthorized
'authorized'/'denied'/'not determined'
Gets the location permission info of the host client.
locationReducedAccuracy
boolean
Location accuracy. true indicates approximate location, while false indicates precise location (iOS only).
microphoneAuthorized
'authorized'/'denied'/'not determined'
Gets the microphone permission info of the host client.
notificationAuthorized
'authorized'/'denied'/'not determined'
Gets the notification permission info of the host client.
notificationAlertAuthorized
'authorized'/'denied'/'not determined'
Gets the reminder permission info of the host client. (iOS only).
notificationBadgeAuthorized
'authorized'/'denied'/'not determined'
Gets the notification badge permission info of the host client. (iOS only).
notificationSoundAuthorized
'authorized'/'denied'/'not determined'
Gets the sound notification permission info of the host client. (iOS only).
phoneCalendarAuthorized
'authorized'/'denied'/'not determined'
Gets the calendar permission info of the host client.
Example:
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 called using UpdateManager wx.getUpdateManager().
Feature description: Gets the globally unique version update manager, used for managing the mini program updates.
Return value: UpdateManager object.

UpdateManager

.applyUpdate

This method is called using UpdateManager.applyUpdate().
Feature description:Forces the mini program to restart and use the new version. It is called after the new version of the mini program is downloaded (i.e. upon receipt of the onUpdateReady callback).

.onCheckForUpdate

This method is called using UpdateManager.onCheckForUpdate(function listener).
Feature description:Requests the backend to check for updates. This process is automatically triggered during the mini program's cold start, so developers don't need to initiate it manually.
Parameter and description:function callback. A callback function for the event that requests the backend to check for updates.
Property
Type
Description
hasUpdate
Boolean
Checks if a new version is available.

.onUpdateFailed

This method is called using UpdateManager.onUpdateFailed(function listener).
Feature description:Listens for mini program update failure event. When a new version of the mini program is available, the client automatically initiates the download (no developer action required). If the download fails (possibly due to network issues), this callback is triggered.
Parameter and description:function callback. A callback function for the event when the mini program update fails.

.onUpdateReady

This method is called using UpdateManager.onUpdateReady(function listener).
Feature description:Listens for mini program update event. The client initiates the download (no developer triggering required). Once the download is successful, this callback is triggered.
Parameter and description:function callback. A callback function for the event when a new version of the mini program is available.
Example:
const updateManager = wx.getUpdateManager()

updateManager.onCheckForUpdate(function (res) {
// Callback after requesting new version information
console.log(res.hasUpdate)
})

updateManager.onUpdateReady(function () {
wx.showModal({
title: 'Update prompt',
content: 'A 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

This API is called using Object wx.getLaunchOptionsSync().
Note:
In some versions,referrerInfo may return undefined.It is recommended to use options.referrerInfo && options.referrerInfo.appId.
Feature description:Gets the parameters when the mini program launches.
Return value:Object, launch parameters.
Property
Type
Description
path
String
The path used to launch the mini program. (for mini programs only).
scene
Number
The scene value when the mini program is launched, default is 1001.
query
Object
The query parameters used to launch the mini program.
referrerInfo
Object
The referrer of the information, returned when entering a mini program from another mini program or an app. Otherwise, it returns {}.
forwardMaterials
Array.<Object>
An array of opened file information.
referrerInfo structure
Property
Type
Description
appId
String
The referrer's AppID for the mini program or app.
extraData
Object
Data passed from the referrer of the mini program.
Note:
extraData is the extended parameter passed from the client when the mini program launches.
For iOS: It is the paramsStr parameter passed in the startUMiniAppWithAppID method.
[[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:@"mpbz0uqwzddj5zbt" scene:TMAEntrySceneNone firstPage:nil paramsStr:@"a=1&amp;b=2" parentVC:self completion:^(NSError * _Nullable err) {

}];
For Android: It is the params field of the MiniStartLinkOptions object.

MiniStartLinkOptions miniStartOptions = new MiniStartLinkOptions(); miniStartOptions.params = (String) options.get("params");
public static void startMiniApp(Activity activity, String appId, MiniStartOptions options) { startMiniApp(activity, appId, 1001, 0, options);
}

forwardMaterials structure
Property
Type
Description
type
string
The MIME type of the file.
name
Object
File name.
path
string
File path.
size
number
File size.
Scenes with valid referrerInfo returned
Property
Type
Description
1037
Opens the mini program from another mini program
The referrer of the mini program.
1038
Returns from another mini program
The referrer of the mini program.

getEnterOptionsSync

This API is called using Object wx.getEnterOptionsSync().
Note:
In some versions,referrerInfo may return undefinedIt is recommended to use options.referrerInfo && options.referrerInfo.appId.
Feature description:Gets the parameters when the mini program launches. If it is a cold start, the return value is consistent with the callback parameter of App.onLaunch. If it is a hot start, the return value is consistent with App.onShow.
Return value:Object
Property
Type
Description
path
string
The path used to launch the mini program (code package path). (for mini programs only).
scene
number
The scene value used to launch the mini program.
query
Object
The query parameters used to launch the mini program.
shareTicket
string
shareTicket
referrerInfo
Object
The information of the referrer. Returned when the mini program is accessed from another mini program or an app. Otherwise, {} is returned. For details, see the note above the table.
forwardMaterials
Array.<Object>
An array of opened file information.
referrerInfo structure
Property
Type
Description
appId
String
The referrer's AppID for the mini program or app.
extraData
Object
Data passed from the referrer of the mini program.
forwardMaterials structure
Property
Type
Description
type
String
The MIME type of the file.
name
Object
File name.
path
String
File path, or URL if using web-view component.
size
Number
File size.
Scenes with valid referrerInfo returned
Property
Type
Description
1037
Opens the mini program from another mini program
The referrer of the mini program.
1038
Returns from another mini program
The referrer of the mini program.

App-level events

onError

This API is called using wx.onError(function callback).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Listens for mini program error event, such as script errors or API call failures.
Parameter and description:function callback. A callback function for mini program error event.
Response parameters: string error, error information, including the stack.

offError

This API is called using wx.offError(function callback).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Cancels listening for mini program errors.
Parameter and description:function callback. A callback function for mini program error event.

onThemeChange

This API is called using wx.onThemeChange(function listener).
Note:
This event is triggered only when darkmode:true is set in the global configuration.
This API is supported in mini programs but not in mini games.
Feature description:Listens for system theme change event.
Parameter and description: function listener, the listener for system theme change event.
Response parameters:Object res
Property
Valid values and description
Type
Description
theme
Dark: Dark theme
Light: Light theme
String
The current theme of the system, with the value is light or dark.

offThemeChange

This API is called using wx.offThemeChange(function listener).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Removes the listener for system theme change event.
Parameter and description:function listener. A listener passed to onThemeChange. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

wx.onThemeChange(listener)
wx.offThemeChange(listener) // Must pass the same function object used in onThemeChange

onPageNotFound

This API is called using wx.onPageNotFound(function listener).
Note:
This API is supported in mini programs but not in mini games.
Note:
Developers can perform page redirection within the callback, but it must be handled synchronously. Asynchronous processing (such as asynchronous execution with setTimeout) is invalid.
If the developer does not call wx.onPageNotFound to bind the listener, and does not state App.onPageNotFound, the host client will display a native "page not found" error page when attempting to navigate to a non-existent page.
If the callback redirects to another page that does not exist, the host client will display the native "page not found" error page and will not trigger the callback a second time.
Feature description:Listens for the event when the mini program attempts to open a non-existent page. This event is triggered at the same time as the App.onPageNotFound.
Parameter and description:Object res parameter, function listener, the listener for the event when the mini program attempts to open a non-existent page.
Property
Type
Description
path
string
The path of the non-existent page (code package path).
query
Object
Query parameter for opening a non-existent page.
isEntryPage
boolean
Whether it is the first page of this launch (for example, when entering from a shared link, the first page is the share page configured by the developer).

offPageNotFound

This API is called using wx.offPageNotFound(function listener).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Removes the listener for the event when the mini program attempts to open a non-existent page.
Parameter and description: function listener. A listener passed to onPageNotFound. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

wx.onPageNotFound(listener)
wx.offPageNotFound(listener) // Must pass the same function object used in onPageNotFound

onAppShow

This API is called using wx.onAppShow(function listener).
Note:
This API is supported in mini programs but not in mini games.
Note:
In some versions, referrerInfo may return undefined if not present. It is recommended to check using options.referrerInfo && options.referrerInfo.appId.
Feature description:Listens for the event when the mini program switches to the frontend. This event is triggered at the same time as the  App.onShow.
Parameter and description:Object res parameter, function listener, the listener for the event when the mini program switches to the frontend.
Property
Type
Description
path
string
The path used to launch the mini program (code package path).
scene
number
The scene value used to launch the mini program.
query
Object
The query parameters used to launch the mini program.
shareTicket
string
shareTicket
referrerInfo
Object
The information of the referrer. Returned when the mini program is accessed from another mini program or an app. Otherwise, {} is returned. For details, see the note above the table.
forwardMaterials
Array.<Object>
An array of opened file information.
referrerInfo structure
Property
Type
Description
appId
string
The referrer's AppID for the mini program or app.
extraData
Object
Data passed from the referrer of the mini program.
forwardMaterials structure
Property
Type
Description
type
String
The MIME type of the file.
name
Object
File name.
path
String
File path, or URL if using web-view component.
size
Number
File size.
Scenes with valid referrerInfo returned
Scene value
Scene
Description
1037
Opens the mini program from another mini program
The referrer of the mini program.
1038
Returns from another mini program
The referrer of the mini program.

offAppShow

This API is called using wx.offAppShow(function listener).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Removes the listener for the event when the mini program switches to the backend.
Parameter and description: function listener. A listener passed to onAppShow. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

wx.onAppShow(listener)
wx.offAppShow(listener) // Must pass the same function object used in onAppShow

onAppHide

This API is called using wx.onAppHide(function listener).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Listens for the event when the mini program switches to the backend. This event is triggered at the same time as the App.onHide.
Parameter and description: function listener. A listener for events of mini program switching to the backend.

offAppHide

The API is called using wx.offAppHide(function listener).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Removes the listener for the event when the mini program switches to the backend.
Parameter and description: function listener. A listener passed to onAppHide. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

wx.onAppHide(listener)
wx.offAppHide(listener) // Must pass the same function object used in onAppHide

onShow

This API is called using wx.onShow(function listener).
Note:
This API is only supported in mini games.
Feature description:A listener for the event when the mini game switches to the frontend.
Parameter and description:Object res parameter, function listener, a listener for the event when the mini game switches to the frontend.
Property
Type
Description
scene
number
Scene value.
query
Object
Query parameter.
shareTicket
string
shareTicket
referrerInfo
Object
The information of the referrer. Returned when the mini program is accessed from another mini program or an app.
referrerInfo structure
Property
Type
Description
appId
string
The referrer's AppID for the mini program or app.
extraData
Object
Data passed from the referrer of the mini program.

offShow

This API is called using wx.offShow(function listener).
Note:
This API is only supported in mini games.
Feature description:Removes the listener for the event when the mini game switches to the frontend.
Parameter and description:function listener. A listener passed to onShow. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

wx.onShow(listener)
wx.offShow(listener) // Must pass the same function object used in onShow

onHide

This API is called using wx.onHide(function listener).
Note:
This API is only supported in mini games.
Feature description:Listens for the event when the mini game switches to the backend. This event is triggered when the user locks the screen or press the Home button to return to the home screen.
Parameter and description:function listener. A listener for the event when the mini game switches to the backend.

offHide

The API is called using wx.offHide(function listener).
Note:
This API is only supported in mini games.
Feature description:Removes the listener for the event when the mini game switches to the backend.
Parameter and description:function listener. A listener passed to onHide. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

wx.onHide(listener)
wx.offHide(listener) // Must pass the same function object used in onHide

onUnhandledRejection

This API is called using wx.onUnhandledRejection(function listener).
Note:
This API is supported in mini programs but not in mini games.
Note:
All unhandledRejection events can be captured by this listener, but only those of the error type will trigger an alert in the mini program backend.
Feature description:Listens for unhandled Promise rejection event.
Parameter and description:Object res parameter, function listener, the listener for unhandled Promise rejection event.
Property
Type
Description
reason
string
Rejection reason, typically an Error object.
promise
Promise.<any>
The rejected Promise object.

offUnhandledRejection

This API is called using wx.offUnhandledRejection(function listener).
Note:
This API is supported in mini programs but not in mini games.
Feature description:Removes the listener for unhandled Promise rejection event.
Parameter and description: function listener. A listener passed to onUnhandledRejection. If not provided, all listeners will be removed.
Example
const listener = function (res) { console.log(res) }

wx.onUnhandledRejection(listener)
wx.offUnhandledRejection(listener) // Must pass the same function object used in onUnhandledRejection

Debug

setEnableDebug

This API is called using wx.setEnableDebug(Object object).
Feature description:Sets whether to enable the debugging. It is also effective in the released version.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
enableDebug
boolean
-
True
Whether to enable debugging.
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
// Enable debugging
wx.setEnableDebug({
enableDebug: true
})

// Disable debugging
wx.setEnableDebug({
enableDebug: false
})
Note:
You can also enable debugging in the development version or preview version first, and then switch to the released version where you can see the vConsole.

getRealtimeLogManager

This API is called using RealtimeLogManager wx.getRealtimeLogManager().
Feature description: Gets the real-time log manager object.
Example
// For the mini program
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])


// For the plugin. Supported on the basic library 2.16.0 and later versions, and only reporting in the new key-value format is allowed.
const logManager = wx.getRealtimeLogManager()
const logger = logManager.tag('plugin-log1')
logger.info('key1', 'value1')
logger.error('key2', {str: 'value2'})
logger.warn('key3', 'value3')

getLogManager

Th is API is called using LogManager wx.getLogManager(Object object).
Feature description:Gets the log manager object.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
level
number
0
False
The valid values are 0 and1, where 0 indicates the calls of lifecycle functions ofApp and Page, , as well as function calls under the namespace, will be logged. A value of 1 means they will not be logged. The default value is 0.
Return value: LogManager.
Example:
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

The console is a global object that can be accessed directly, with a set of features as follows. You can print logs in the IDE debugging panel and use vConsole to output logs on the client.

LogManager

The log manager instance, which can be accessed using getLogManager, with the set of features as follows.

RealtimeTagLogManager

Performance

Note:
Only supported in mini games.

triggerGC

This API is called using wx.triggerGC().
Feature description:Accelerates triggering JavaScriptCore garbage collection. The timing of garbage collection is controlled by JavaScriptCore, and it cannot guarantee that garbage collection is triggered immediately after the call.

getPerformance

This API is called using wx.getPerformance().
Feature description:Gets performance manager.
Return value: Performance, a performance manager object.

Performance

.now

This method is called using Performance.now().
Feature description:Gets the current timestamp in microseconds.
Return value: number, a timestamp.


Subpackage loading

Note:
Only supported in mini games.

preDownloadSubpackage

This method is called using wx.preDownloadSubpackage(Object object).
Feature description:Triggers subpackage pre-download.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
packageType
string
'normal'
False
Subpackage type. The name field becomes invalid if you enter "workers" for this property.
name
string

True
Subpackage name. You can enter name or root. In an independent subpackage, __GAME__ indicates loading the main package.
success
function

True
Callback function for successful subpackage loading.
fail
function

True
Callback function for failed subpackage loading.
complete
function

True
Callback function executed after the subpackage loading ends (regardless of success or failure).
Return value: PreDownloadSubpackageTask. Instance of a subpackage pre-download task, used to get the pre-download status of the subpackage.
Note:The difference between wx.preDownloadSubpackage and wx.loadSubpackage: wx.preDownloadSubpackage is only used to download the code package without automatically executing the code, and wx.loadSubpackage will automatically execute the code after downloading the code package.
Example:
Example for worker subpackage:
// Configure workers as a subpackage in app.json / game.json first
{
"workers": {
"path": "myWorkersFolder",
"isSubpackage": true // true means the worker is packaged as a subpackage Default value: False. If false, it is equivalent to { "workers": "myWorkersFolder" }
}
}
// Call wx.preDownloadSubpackage to download the worker subpackage. Only after the download is successful can you create the worker
var task = wx.preDownloadSubpackage({
packageType: "workers",
success(res) {
console.log("load worker success", res)
wx.createWorker("myWorkersFolder/request/index.js") // Create worker. If the worker subpackage is not fully downloaded, calling createWorker will result in an error.
},
fail(res) {
console.log("load worker fail", res)
}
})

task.onProgressUpdate(res => {
console.log(res.progress) // Listen to download progress using onProgressUpdate
console.log(res.totalBytesWritten)
console.log(res.totalBytesExpectedToWrite)
})

Example for ordinary subpackage:
// Configure the subpackage in app.json / game.json first
{
"subPackages": [
{
"name": "ModuleA",
"root": "/ModuleA/"
}
]
}
var task = wx.preDownloadSubpackage({
name: "ModuleA",
success(res) {
console.log("load subpackage success", res)
// Execute the subpackage code
wx.loadSubpackage({
name: "ModuleA",
success(res) {
console.log(res)
},
})
},
fail(res) {
console.log("load subpackage fail", res)
}
})

task.onProgressUpdate(res => {
console.log(res.progress) // Listen to download progress using onProgressUpdate
console.log(res.totalBytesWritten)
console.log(res.totalBytesExpectedToWrite)
})

PreDownloadSubpackageTask

.onProgressUpdate

This method is called using PreDownloadSubpackageTask.onProgressUpdate(function listener).
Feature description:Listens for subpackage loading progress update event.
Parameter and description:function listener. The listener for subpackage loading progress update event. See the parameter Object.res as below.
Property
Type
Description
progress
number
Subpackage download progress in percentage.
totalBytesWritten
number
The downloaded data length in bytes.
totalBytesExpectedToWrite
number
The total length of data expected to be downloaded, in bytes.

loadSubpackage

This method is called using wx.loadSubpackage(Object object).
Feature description:Triggers subpackage loading.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
packageType
string
'normal'
False
Subpackage type. The name field becomes invalid if you enter "workers" for this property.
name
string

True
Subpackage name. You can enter name or root. In an independent subpackage, __GAME__ indicates loading the main package.
success
function

True
Callback function for successful subpackage loading.
fail
function

True
Callback function for failed subpackage loading.
complete
function

True
Callback function executed after the subpackage loading ends (regardless of success or failure).
Return value:LoadSubpackageTask. Instance of a subpackage loading task, used to get the loading status of the subpackage.
Note:The difference between wx.preDownloadSubpackage and wx.loadSubpackage: wx.preDownloadSubpackage is only used to download the code package without automatically executing the code, and wx.loadSubpackage will automatically execute the code after downloading the code package.

LoadSubpackageTask

.onProgressUpdate

This method is called using LoadSubpackageTask.onProgressUpdate(function listener).
Feature description:Listens for subpackage loading progress update event.
Parameter and description:function listener. The listener for subpackage loading progress update event. See the parameter Object.res as below.
Property
Type
Description
progress
number
Subpackage download progress in percentage.
totalBytesWritten
number
The length of data that has been downloaded, in bytes.
totalBytesExpectedToWrite
number
The total length of data expected to be downloaded, in bytes.


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

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 available.

7x24 Phone Support