如何捕获 js 错误的调用栈,我现在捕获错误的内容如下:
$_REQUEST = array (
'app_id' => 'A6125757481738',
'auth_code' => 'c9f0f8',
'access_token' => 'ec47cc',
'time_now' => '1710323849',
'client' => 'h5',
'ver' => '1.1',
'sid' => '12ef4dbe86f4a22de46e7f57d5456598',
'action' => 'reportErrorToS',
'app_ver' => '0.0.29',
'msg' => '{"line":2,"column":18280,"error":"Uncaught TypeError: Cannot read properties of null (reading \'querySelector\')","url":"https://www.taobao.top/style.php?t=js&p=record&v=1710307222","info":{},"curl":"https://www.taobao.top/record.html"}',
)
我页面的 js 是压缩的,现在这个错误报告非常的不容易定位,我上报错误的代码如下:
window.onerror = function (errorMessage, scriptURI, lineNumber, columnNumber, errorObj) {
reportErrorToS(JSON.stringify({
line: lineNumber,
column: columnNumber,
error: encodeURIComponent(errorMessage),
url: encodeURIComponent(scriptURI),
info: errorObj,
curl: encodeURIComponent(location.href)
}));
};
我想请问一下能否像 php 那样打印整个调用栈,从最开始的入口处一直调用到具体的错误处。
你需要用 sourcemap 文件才能还原。
https://docs.fundebug.com/notifier/javascript/sourcemap/