Skip to content

Commit d430687

Browse files
#6128 Use stripped url for exception (#6131)
* fix: strip gmail url from report * feat: added test
1 parent ba1e0a1 commit d430687

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

extension/js/common/platform/catch.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class Catch {
174174

175175
public static environment(url = location.href): string {
176176
const browserName = Catch.browser().name;
177-
const origin = new URL(location.href).origin;
177+
const origin = new URL(url).origin;
178178
let env = 'unknown';
179179
if (url.includes('bnjglocicd')) {
180180
env = 'ex:prod';
@@ -262,12 +262,14 @@ export class Catch {
262262
}
263263
}
264264
const exception = Catch.formExceptionFromThrown(thrown);
265+
const reportUrl = location.href.split('?')[0];
265266
return {
266267
name: exception.name.substring(0, 50),
267268
message: Catch.groupSimilarReports(exception.message.substring(0, 200)),
268-
// Use https://mail.google.com/mail as URL for content script errors
269+
// Strip Gmail URLs to group similar errors from different threads/messages
269270
// https://github.com/FlowCrypt/flowcrypt-browser/issues/6031
270-
url: Catch.RUNTIME_ENVIRONMENT === 'ex:s:gmail' ? 'https://mail.google.com/mail' : Catch.groupSimilarReports(location.href.split('?')[0]),
271+
// https://github.com/FlowCrypt/flowcrypt-browser/issues/6128
272+
url: Catch.RUNTIME_ENVIRONMENT.endsWith(':ex:s:gmail') ? 'https://mail.google.com/mail/' : Catch.groupSimilarReports(reportUrl),
271273
line: line || 1,
272274
col: col || 1,
273275
trace: Catch.groupSimilarReports(exception.stack || ''),

test/source/tests/browser-unit-tests/unit-Catch.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,34 @@ BROWSER_UNIT_TEST_NAME(`Catcher does not include query string on report`);
7070
}
7171
return 'pass';
7272
})();
73+
74+
BROWSER_UNIT_TEST_NAME(`Catcher reports correct URL for Gmail environment`);
75+
(async () => {
76+
const originalEnv = Catch.RUNTIME_ENVIRONMENT;
77+
78+
// https://github.com/FlowCrypt/flowcrypt-browser/issues/6128
79+
const sensitivePaths = [
80+
'/mail/u/0/#inbox/WhctKLbvMNLndrHSj',
81+
'/mail/u/0/#sent/KtbxLzFrMS',
82+
'/mail/u/1/#inbox/rtjXfHsNNgrJVZL',
83+
'/mail/u/1/#search/MSCGwzQrb',
84+
];
85+
86+
try {
87+
for (const path of sensitivePaths) {
88+
const fullUrl = 'https://mail.google.com' + path;
89+
90+
// Simulate environment detection based on the URL
91+
const env = Catch.environment(fullUrl);
92+
Catch.RUNTIME_ENVIRONMENT = env;
93+
94+
const formatted = Catch.formatExceptionForReport({ name: 'Error' });
95+
if (formatted.url !== 'https://mail.google.com/mail/') {
96+
throw new Error(`For path ${path}, expected URL to be 'https://mail.google.com/mail/' but got '${formatted.url}' (env: ${env})`);
97+
}
98+
}
99+
} finally {
100+
Catch.RUNTIME_ENVIRONMENT = originalEnv;
101+
}
102+
return 'pass';
103+
})();

0 commit comments

Comments
 (0)