From 4a6267651217b21a098fc9d1cb1d16be8e81103d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 11 Dec 2023 14:22:44 +0000 Subject: [PATCH] DEV: Identify errors/deprecations triggered by browser extensions (#24820) It's possible for browser extensions to trigger JS errors and deprecation warnings. That can lead to significant confusion and noise in our logs/metrics. One recent example we've identified is the 'Wappalyzer' extension triggering the `ember-global` deprecation. This commit will clearly identify these errors/deprecations with a `[BROWSER EXTENSION]` prefix in the console. --- .../discourse/app/lib/source-identifier.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/assets/javascripts/discourse/app/lib/source-identifier.js b/app/assets/javascripts/discourse/app/lib/source-identifier.js index f27605c111f..bd64582bda1 100644 --- a/app/assets/javascripts/discourse/app/lib/source-identifier.js +++ b/app/assets/javascripts/discourse/app/lib/source-identifier.js @@ -2,6 +2,12 @@ import DEBUG from "@glimmer/env"; import PreloadStore from "discourse/lib/preload-store"; import getURL from "discourse-common/lib/get-url"; +const BROWSER_EXTENSION_PROTOCOLS = [ + "moz-extension://", + "chrome-extension://", + "webkit-masked-url://", +]; + export default function identifySource(error) { if (!error || !error.stack) { try { @@ -22,6 +28,12 @@ export default function identifySource(error) { "" ); + if (BROWSER_EXTENSION_PROTOCOLS.any((p) => stack.includes(p))) { + return { + type: "browser-extension", + }; + } + const themeMatches = stack.match(/\/theme-javascripts\/[\w-]+\.js/g) || []; for (const match of themeMatches) { @@ -72,6 +84,8 @@ export function consolePrefix(error, source) { return `[THEME ${source.id} '${source.name}']`; } else if (source && source.type === "plugin") { return `[PLUGIN ${source.name}]`; + } else if (source && source.type === "browser-extension") { + return "[BROWSER EXTENSION]"; } return "";