uni-app reportJSException
uni-app reportJSException
| 项目信息 | 详细信息 |
|---|---|
| 产品分类 | uniapp/App |
| PC开发环境操作系统 | Windows |
| PC开发环境操作系统版本号 | win10 |
| HBuilderX类型 | Alpha |
| HBuilderX版本号 | 4.01 |
| 手机系统 | Android |
| 手机系统版本号 | Android 12 |
| 手机厂商 | 华为 |
| 手机机型 | 荣耀60 |
| 页面类型 | vue |
| vue版本 | vue3 |
| 打包方式 | 云端 |
| 项目创建方式 | HBuilderX |
操作步骤:
- 在自定义基座模式运行,报错,页面白屏
预期结果:
- app正常运行
实际结果:
- app正常运行
bug描述:
- 打完包后,在自定义基座模式下,一致无法运行,一运行就报这个bug
- reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught TypeError: Cannot read property ‘baseURI’ of undefined
- 我全文没有这个变量呀,而且我4-3号都正常打包的,清明节后再打包,打死不能行。麻烦帮看下,不知道什么情况
- App下载地址或H5网址:m.fx178.cn
更多关于uni-app reportJSException的实战教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于uni-app reportJSException的实战教程也可以访问 https://www.itying.com/category-93-b0.html
reportJSException is a method used in uni-app to report JavaScript exceptions. This method is typically used to capture and log JavaScript errors that occur during the execution of a uni-app application. By reporting these exceptions, developers can identify and fix issues more effectively.
Usage
To use reportJSException, you can call it in your App.vue or other components where you want to catch and report JavaScript errors.
Here’s an example of how you might use it:
// App.vue
export default {
onLaunch() {
// Capture global JavaScript errors
window.onerror = function(message, source, lineno, colno, error) {
uni.reportJSException({
message: message,
source: source,
lineno: lineno,
colno: colno,
stack: error ? error.stack : ''
});
return true; // Prevent the default error handler from firing
};
// Capture unhandled promise rejections
window.onunhandledrejection = function(event) {
uni.reportJSException({
message: event.reason ? event.reason.message : 'Unhandled promise rejection',
stack: event.reason ? event.reason.stack : ''
});
};
}
};
Parameters
The reportJSException method accepts an object with the following properties:
- message: The error message.
- source: The URL of the script where the error occurred.
- lineno: The line number where the error occurred.
- colno: The column number where the error occurred.
- stack: The stack trace of the error.
Example
uni.reportJSException({
message: 'Undefined variable',
source: 'https://example.com/app.js',
lineno: 42,
colno: 13,
stack: 'Error: Undefined variable\n at https://example.com/app.js:42:13'
});

