mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 10:56:10 +01:00 
			
		
		
		
	Don't show third-party JS errors in production builds (#29303)
So we don't get issues like https://github.com/go-gitea/gitea/issues/29080 and https://github.com/go-gitea/gitea/issues/29273 any more. Only active in [production builds](https://webpack.js.org/guides/production/#specify-the-mode), in non-production the errors will still show.
This commit is contained in:
		
							
								
								
									
										15
									
								
								web_src/js/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								web_src/js/bootstrap.js
									
									
									
									
										vendored
									
									
								
							| @@ -29,17 +29,26 @@ export function showGlobalErrorMessage(msg) { | |||||||
|  * @param {ErrorEvent} e |  * @param {ErrorEvent} e | ||||||
|  */ |  */ | ||||||
| function processWindowErrorEvent(e) { | function processWindowErrorEvent(e) { | ||||||
|  |   const err = e.error ?? e.reason; | ||||||
|  |   const assetBaseUrl = String(new URL(__webpack_public_path__, window.location.origin)); | ||||||
|  |  | ||||||
|  |   // error is likely from browser extension or inline script. Do not show these in production builds. | ||||||
|  |   if (!err.stack?.includes(assetBaseUrl) && window.config?.runModeIsProd) return; | ||||||
|  |  | ||||||
|  |   let message; | ||||||
|   if (e.type === 'unhandledrejection') { |   if (e.type === 'unhandledrejection') { | ||||||
|     showGlobalErrorMessage(`JavaScript promise rejection: ${e.reason}. Open browser console to see more details.`); |     message = `JavaScript promise rejection: ${err.message}.`; | ||||||
|     return; |   } else { | ||||||
|  |     message = `JavaScript error: ${e.message} (${e.filename} @ ${e.lineno}:${e.colno}).`; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (!e.error && e.lineno === 0 && e.colno === 0 && e.filename === '' && window.navigator.userAgent.includes('FxiOS/')) { |   if (!e.error && e.lineno === 0 && e.colno === 0 && e.filename === '' && window.navigator.userAgent.includes('FxiOS/')) { | ||||||
|     // At the moment, Firefox (iOS) (10x) has an engine bug. See https://github.com/go-gitea/gitea/issues/20240 |     // At the moment, Firefox (iOS) (10x) has an engine bug. See https://github.com/go-gitea/gitea/issues/20240 | ||||||
|     // If a script inserts a newly created (and content changed) element into DOM, there will be a nonsense error event reporting: Script error: line 0, col 0. |     // If a script inserts a newly created (and content changed) element into DOM, there will be a nonsense error event reporting: Script error: line 0, col 0. | ||||||
|     return; // ignore such nonsense error event |     return; // ignore such nonsense error event | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   showGlobalErrorMessage(`JavaScript error: ${e.message} (${e.filename} @ ${e.lineno}:${e.colno}). Open browser console to see more details.`); |   showGlobalErrorMessage(`${message} Open browser console to see more details.`); | ||||||
| } | } | ||||||
|  |  | ||||||
| function initGlobalErrorHandler() { | function initGlobalErrorHandler() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user