From 941a2311f02f841da0205f6c61a2f9f32d5df30e Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 21 Sep 2023 11:31:07 +0200 Subject: [PATCH] webmail: try a bit harder not to get mailbox names or search queries in the potential stacktrace we want to user to submit the stack trace. user can still edit before submitting, but it won't look attractive to submit stacktraces with info that shouldn't be there. not great that firefox is including too much info and the effort we need to make to get it out again, but well. --- webmail/webmail.js | 15 ++++++++++++--- webmail/webmail.ts | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/webmail/webmail.js b/webmail/webmail.js index d02b840..ce800bb 100644 --- a/webmail/webmail.js +++ b/webmail/webmail.js @@ -5829,6 +5829,14 @@ window.addEventListener('load', async () => { window.alert('Error: ' + errmsg(err)); } }); +// Keep original URL of page load, so we can remove it from stack trace if we need to. +const origLocation = { + href: window.location.href, + protocol: window.location.protocol, + host: window.location.host, + pathname: window.location.pathname, + search: window.location.search, +}; // If a JS error happens, show a box in the lower left corner, with a button to // show details, in a popup. The popup shows the error message and a link to github // to create an issue. We want to lower the barrier to give feedback. @@ -5839,9 +5847,10 @@ const showUnhandledError = (err, lineno, colno) => { } let stack = err.stack || ''; if (stack) { - // Firefox has stacks with full location.href including hash at the time of - // writing, Chromium has location.href without hash. - const loc = window.location; + log({ stack }); + // At the time of writing, Firefox has stacks with full location.href of original + // page load including hash. Chromium has location.href without hash. + const loc = origLocation; stack = '\n' + stack.replaceAll(loc.href, 'webmail.html').replaceAll(loc.protocol + '//' + loc.host + loc.pathname + loc.search, 'webmail.html'); } else { diff --git a/webmail/webmail.ts b/webmail/webmail.ts index 97e1035..dbac731 100644 --- a/webmail/webmail.ts +++ b/webmail/webmail.ts @@ -6220,6 +6220,15 @@ window.addEventListener('load', async () => { } }) +// Keep original URL of page load, so we can remove it from stack trace if we need to. +const origLocation = { + href: window.location.href, + protocol: window.location.protocol, + host: window.location.host, + pathname: window.location.pathname, + search: window.location.search, +} + // If a JS error happens, show a box in the lower left corner, with a button to // show details, in a popup. The popup shows the error message and a link to github // to create an issue. We want to lower the barrier to give feedback. @@ -6230,10 +6239,11 @@ const showUnhandledError = (err: Error, lineno: number, colno: number) => { } let stack = err.stack || '' if (stack) { - // Firefox has stacks with full location.href including hash at the time of - // writing, Chromium has location.href without hash. - const loc = window.location - stack = '\n'+stack.replaceAll(loc.href, 'webmail.html').replaceAll(loc.protocol+'//'+loc.host+loc.pathname+loc.search, 'webmail.html') + log({stack}) + // At the time of writing, Firefox has stacks with full location.href of original + // page load including hash. Chromium has location.href without hash. + const loc = origLocation + stack = '\n'+stack.replaceAll(loc.href, 'webmail.html').replaceAll(loc.protocol + '//' + loc.host + loc.pathname + loc.search, 'webmail.html') } else { stack = ' (not available)' }