Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// // instead of doing the sane code of being able to just use import.meta.url
// // (Edge doesn't work) (safari mobile, chrome, opera, firefox all do)
// //
// // I will use stacktrace-js library to get the current file name
// //
// try {
// // @ts-ignore
// let packageUrl = import.meta.url;
// currentJavascriptURL = packageUrl;
// } catch (error) {
// // eat
// }
//
//
{
let stacktrace = StackTrace.getSync();
currentJavascriptURL = stacktrace[0].fileName;
}
const magickWorkerUrl = GetCurrentUrlDifferentFilename('magick.js')
function GenerateMagickWorkerText(magickUrl){
// generates code for the following
// var magickJsCurrentPath = 'magickUrl';
// importScripts(magickJsCurrentPath);
return "var magickJsCurrentPath = '" + magickUrl +"';\n" +
'importScripts(magickJsCurrentPath);'
}
let magickWorker;
if(currentJavascriptURL.startsWith('http'))
{
// // instead of doing the sane code of being able to just use import.meta.url
// // (Edge doesn't work) (safari mobile, chrome, opera, firefox all do)
// //
// // I will use stacktrace-js library to get the current file name
// //
// try {
// // @ts-ignore
// let packageUrl = import.meta.url;
// currentJavascriptURL = packageUrl;
// } catch (error) {
// // eat
// }
//
//
{
let stacktrace = StackTrace.getSync();
currentJavascriptURL = stacktrace[0].fileName;
}
const magickWorkerUrl = GetCurrentUrlDifferentFilename('magick.js')
function GenerateMagickWorkerText(magickUrl){
// generates code for the following
// var magickJsCurrentPath = 'magickUrl';
// importScripts(magickJsCurrentPath);
return "var magickJsCurrentPath = '" + magickUrl +"';\n" +
'importScripts(magickJsCurrentPath);'
}
let magickWorker;
if(currentJavascriptURL.startsWith('http'))
{
handleError(error: Error) {
const loggingService = this._injector.get(LoggingService);
const location = this._injector.get(LocationStrategy);
const message = error.message ? error.message : error.toString();
const url = location instanceof PathLocationStrategy ? location.path() : "";
/**
* TODO: 想一下怎么做一个简单的APM
* 最好都用elk技术栈配合skywalking前后一条龙
* 1. 记录首屏加载,文档加载(DOMContentLoaded),页面加载(load),脚本错误,慢路由
* 2. 跟踪业务流程
* 3. 离线存储和在线存储
* 4. 生成Source-map,webpack打包后的代码报错你是trace不到的
* 5. 错误预警,统计报表
*/
// get the stack trace, lets grab the last 10 stacks only
StackTrace.fromError(error).then(stackframes => {
const stackString = stackframes
.splice(0, 20)
.map(function(sf) {
return sf.toString();
})
.join("\n");
// log on the server
loggingService.error({ message, url, stack: stackString });
});
throw error;
}
}
function resolveError(err, firstFrameIndex) {
// This will use sourcemaps and normalize the stack frames
return StackTrace.fromError(err).then(function(stack) {
var lines = [err.toString()];
// Reconstruct to a JS stackframe as expected by Error Reporting parsers.
for (var s = firstFrameIndex; s < stack.length; s++) {
// Cannot use stack[s].source as it is not populated from source maps.
lines.push([
' at ',
// If a function name is not available '' will be used.
stack[s].getFunctionName() || '', ' (',
stack[s].getFileName(), ':',
stack[s].getLineNumber(), ':',
stack[s].getColumnNumber(), ')',
].join(''));
}
return lines.join('\n');
}, function(reason) {
// Failure to extract stacktrace
const e = new Error()
if (typeof error === 'string') {
e.name = error
e.message = error
} else if (typeof error === 'number') {
e.name = error.toString()
e.message = error.toString()
} else if (error instanceof Error) {
e.name = error.name
e.message = error.message
e.stack = error.stack
} else {
e.name = 'unknown'
e.message = 'unknown'
}
StackTrace.fromError(e, { offline: true }).then(frames => {
// Crashlytics.recordCustomExceptionName(e.message, e.message, frames)
const updatedFrames = frames.map(row => ({
lineNumber: row.lineNumber,
columnNumber: row.columnNumber,
functionName: row.functionName,
fileName: `${row.fileName}:${row.lineNumber || 0}:${row.columnNumber ||
0}`
}))
Firebase.crashlytics().recordError(0, e.message)
// Crashlytics.recordCustomExceptionName(e.message, e.message, updatedFrames)
})
if (originalHandler) {
if (Platform.OS === 'ios') {
originalHandler(error, isFatal)
} else {
// On Android, throwing the original exception immediately results in the
handleError(error) {
if (Lib.DevMode()){
throw error;
}
// const loggingService = this.injector.get(LoggingService);
// const location = this.injector.get(LocationStrategy);
// const url = location instanceof PathLocationStrategy ? location.path() : '';
var message = error.message ? error.message : error.toString();
var url = 'https://secure.digitalsignage.com/stacktrace/';
// get the stack trace, lets grab the last 10 stacks only
StackTrace.fromError(error).then(stackframes => {
const stackString = stackframes
.splice(0, 20)
.map(function (sf) {
return sf.toString();
}).join('\n');
var date = moment().format('YYYY-MM-DD h:mm:ss');
message = `error :: business :: ${window['business_id']} :: studiolite :: ${date} :: ${message}`
StackTrace.report(stackString, url, message);
});
throw error;
}
uncaught.addListener(err => {
// this will transform the error's `stack` property
// to be consistently similar to Gecko and V8 stackframes
StackTrace.fromError(err)
.then(stackframes => {
err.stack = prepareStackTrace(err, stackframes);
logger.error(err);
})
.catch(err_ => {
logger.error(err);
logger.error(err_);
});
});
return new Promise((resolve: any) => {
// This one has a promise too
ST.fromError(error, {offline: true}).then((frames: ST.StackFrame[]) => {
const stackStr = (frames.map((frame: ST.StackFrame) => {
return frame.toString();
}) ).join("\n ");
result += "\n" + stackStr;
// This resolves our returned promise
resolve(result);
}).catch(() => {
result = "Unexpected error object was passed in. ";
try {
result += "Could not resolve it, stringified object: " + JSON.stringify(error);
}
catch (e) {
// Cannot stringify can only tell something was wrong.
result += "Could not resolve it or stringify it.";
private async mkMessage(severity: string, msg: string): Promise {
const trace = await StackTrace.get()
// Shift off the generated promise wrappers.
for (let i = 0; i < 11; i++) {
if (trace[0].fileName.match(/.*(main|zone)\.js$/) ||
trace[0].fileName.match(/.*\/node_modules\/.*/)) {
trace.shift();
} else {
break;
}
}
const fn = trace[0].fileName.replace('webpack://', '');
const message = new LogMessage(
severity, msg,
`${trace[0].functionName} (${fn}:${trace[0].lineNumber})`, trace);
this.messages.push(message);
this.messagesSubject.next(this.messages);
return traceInfo.cache
}
function parseStacktrace(trace) {
var results = []
for(var n = 0; n