legends810/testingnew
0
1/**2 * Cleans webcontainer URLs from stack traces to show relative paths instead3 */4export function cleanStackTrace(stackTrace: string): string {5 // Function to clean a single URL6 const cleanUrl = (url: string): string => {7 const regex = /^https?:\/\/[^\/]+\.webcontainer-api\.io(\/.*)?$/;8 9 if (!regex.test(url)) {10 return url;11 }12 13 const pathRegex = /^https?:\/\/[^\/]+\.webcontainer-api\.io\/(.*?)$/;14 const match = url.match(pathRegex);15 16 return match?.[1] || '';17 };18 19 // Split the stack trace into lines and process each line20 return stackTrace21 .split('\n')22 .map((line) => {23 // Match any URL in the line that contains webcontainer-api.io24 return line.replace(/(https?:\/\/[^\/]+\.webcontainer-api\.io\/[^\s\)]+)/g, (match) => cleanUrl(match));25 })26 .join('\n');27}28 