Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions extension/js/common/platform/catch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 || ''),
Expand Down
31 changes: 31 additions & 0 deletions test/source/tests/browser-unit-tests/unit-Catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
})();
Loading