Skip to content

Commit e4c3c03

Browse files
DD-PEarl Warren
authored and
Earl Warren
committed
Suppress Monaco JavaScript errors in Safari (go-gitea#3805)
Fix go-gitea#3638 This is a manual Forgejo-specific version of the Gitea PR go-gitea#30862. The weekly Forgejo PR go-gitea#3772 could not cherry-pick this commit due to conflicts (eg subsequent CodeSpell changes). Only occurs with Webkit in Safari over eg `http://192..`. (not localhost). See https://webkit.org/blog/10855/async-clipboard-api/ --- **Before** ![Before.jpg](/attachments/c570d030-fcce-48ea-ac96-06b624541c7b) **After** ![After.jpg](/attachments/1a9132ab-f7f3-43a5-b3ea-37b6f2b671c4) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3805 Reviewed-by: Otto <[email protected]> Co-authored-by: David Davies-Payne <[email protected]> Co-committed-by: David Davies-Payne <[email protected]>
1 parent 11a031e commit e4c3c03

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

web_src/js/bootstrap.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
// This file must be imported before any lazy-loading is being attempted.
77
__webpack_public_path__ = `${window.config?.assetUrlPrefix ?? '/assets'}/`;
88

9+
// Ignore external and some known internal errors that we are unable to currently fix.
10+
function shouldIgnoreError(err) {
11+
const assetBaseUrl = String(new URL(__webpack_public_path__, window.location.origin));
12+
13+
if (!(err instanceof Error)) return false;
14+
// If the error stack trace does not include the base URL of our script assets, it likely came
15+
// from a browser extension or inline script. Ignore these errors.
16+
if (!err.stack?.includes(assetBaseUrl)) return true;
17+
// Ignore some known internal errors that we are unable to currently fix (eg via Monaco).
18+
const ignorePatterns = [
19+
'/assets/js/monaco.', // https://codeberg.org/forgejo/forgejo/issues/3638 , https://github.com/go-gitea/gitea/issues/30861 , https://github.com/microsoft/monaco-editor/issues/4496
20+
];
21+
for (const pattern of ignorePatterns) {
22+
if (err.stack?.includes(pattern)) return true;
23+
}
24+
return false;
25+
}
26+
927
const filteredErrors = new Set([
1028
'getModifierState is not a function', // https://github.com/microsoft/monaco-editor/issues/4325
1129
]);
@@ -47,7 +65,6 @@ export function showGlobalErrorMessage(msg) {
4765
*/
4866
function processWindowErrorEvent({error, reason, message, type, filename, lineno, colno}) {
4967
const err = error ?? reason;
50-
const assetBaseUrl = String(new URL(__webpack_public_path__, window.location.origin));
5168
const {runModeIsProd} = window.config ?? {};
5269

5370
// `error` and `reason` are not guaranteed to be errors. If the value is falsy, it is likely a
@@ -60,11 +77,8 @@ function processWindowErrorEvent({error, reason, message, type, filename, lineno
6077
if (runModeIsProd) return;
6178
}
6279

63-
// If the error stack trace does not include the base URL of our script assets, it likely came
64-
// from a browser extension or inline script. Do not show such errors in production.
65-
if (err instanceof Error && !err.stack?.includes(assetBaseUrl) && runModeIsProd) {
66-
return;
67-
}
80+
// In production do not display errors that should be ignored.
81+
if (runModeIsProd && shouldIgnoreError(err)) return;
6882

6983
let msg = err?.message ?? message;
7084
if (lineno) msg += ` (${filename} @ ${lineno}:${colno})`;

0 commit comments

Comments
 (0)