File size: 1,256 Bytes
bee6636 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import { config, flagEnabled } from "../../shared";
import { unrewriteUrl } from "../../shared/rewriters/url";
import { ScramjetClient } from "../client";
export const enabled = (client: ScramjetClient) =>
flagEnabled("cleanErrors", client.url);
export default function (client: ScramjetClient, _self: Self) {
// v8 only. all we need to do is clean the scramjet urls from stack traces
const closure = (error, stack) => {
let newstack = error.stack;
for (let i = 0; i < stack.length; i++) {
const url = stack[i].getFileName();
if (url.endsWith(config.files.all)) {
// strip stack frames including scramjet handlers from the trace
const lines = newstack.split("\n");
const line = lines.find((l) => l.includes(url));
lines.splice(line, 1);
newstack = lines.join("\n");
continue;
}
try {
newstack = newstack.replaceAll(url, unrewriteUrl(url));
} catch {}
}
return newstack;
};
client.Trap("Error.prepareStackTrace", {
get(_ctx) {
// this is a funny js quirk. the getter is ran every time you type something in console
return closure;
},
set(_value) {
// just ignore it if a site tries setting their own. not much we can really do
},
});
}
|