diff --git a/extension/js/common/platform/catch.ts b/extension/js/common/platform/catch.ts index 79496a4f775..77ed6dffba9 100644 --- a/extension/js/common/platform/catch.ts +++ b/extension/js/common/platform/catch.ts @@ -174,7 +174,7 @@ export class Catch { public static environment(url = location.href): string { const browserName = Catch.browser().name; - const origin = new URL(location.href).origin; + const origin = new URL(url).origin; let env = 'unknown'; if (url.includes('bnjglocicd')) { env = 'ex:prod'; @@ -262,12 +262,14 @@ export class Catch { } } const exception = Catch.formExceptionFromThrown(thrown); + const reportUrl = location.href.split('?')[0]; return { name: exception.name.substring(0, 50), message: Catch.groupSimilarReports(exception.message.substring(0, 200)), - // Use https://mail.google.com/mail as URL for content script errors + // Strip Gmail URLs to group similar errors from different threads/messages // https://github.com/FlowCrypt/flowcrypt-browser/issues/6031 - url: Catch.RUNTIME_ENVIRONMENT === 'ex:s:gmail' ? 'https://mail.google.com/mail' : Catch.groupSimilarReports(location.href.split('?')[0]), + // https://github.com/FlowCrypt/flowcrypt-browser/issues/6128 + url: Catch.RUNTIME_ENVIRONMENT.endsWith(':ex:s:gmail') ? 'https://mail.google.com/mail/' : Catch.groupSimilarReports(reportUrl), line: line || 1, col: col || 1, trace: Catch.groupSimilarReports(exception.stack || ''), diff --git a/test/source/tests/browser-unit-tests/unit-Catch.js b/test/source/tests/browser-unit-tests/unit-Catch.js index 888a8d187cb..b3223022f98 100644 --- a/test/source/tests/browser-unit-tests/unit-Catch.js +++ b/test/source/tests/browser-unit-tests/unit-Catch.js @@ -70,3 +70,34 @@ BROWSER_UNIT_TEST_NAME(`Catcher does not include query string on report`); } return 'pass'; })(); + +BROWSER_UNIT_TEST_NAME(`Catcher reports correct URL for Gmail environment`); +(async () => { + const originalEnv = Catch.RUNTIME_ENVIRONMENT; + + // https://github.com/FlowCrypt/flowcrypt-browser/issues/6128 + const sensitivePaths = [ + '/mail/u/0/#inbox/WhctKLbvMNLndrHSj', + '/mail/u/0/#sent/KtbxLzFrMS', + '/mail/u/1/#inbox/rtjXfHsNNgrJVZL', + '/mail/u/1/#search/MSCGwzQrb', + ]; + + try { + for (const path of sensitivePaths) { + const fullUrl = 'https://mail.google.com' + path; + + // Simulate environment detection based on the URL + const env = Catch.environment(fullUrl); + Catch.RUNTIME_ENVIRONMENT = env; + + const formatted = Catch.formatExceptionForReport({ name: 'Error' }); + if (formatted.url !== 'https://mail.google.com/mail/') { + throw new Error(`For path ${path}, expected URL to be 'https://mail.google.com/mail/' but got '${formatted.url}' (env: ${env})`); + } + } + } finally { + Catch.RUNTIME_ENVIRONMENT = originalEnv; + } + return 'pass'; +})(); \ No newline at end of file